/** * \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() */
/** * Computes REAL4TimeSeries containing time series of response amplitudes. * \see XLALComputeDetAMResponse() for more details. */ int XLALComputeDetAMResponseSeries(REAL4TimeSeries ** fplus, REAL4TimeSeries ** fcross, const REAL4 D[3][3], const double ra, const double dec, const double psi, const LIGOTimeGPS * start, const double deltaT, const int n) { LIGOTimeGPS t; double gmst; int i; double p, c; *fplus = XLALCreateREAL4TimeSeries("plus", start, 0.0, deltaT, &lalDimensionlessUnit, n); *fcross = XLALCreateREAL4TimeSeries("cross", start, 0.0, deltaT, &lalDimensionlessUnit, n); if(!*fplus || !*fcross) { XLALDestroyREAL4TimeSeries(*fplus); XLALDestroyREAL4TimeSeries(*fcross); *fplus = *fcross = NULL; XLAL_ERROR(XLAL_EFUNC); } for(i = 0; i < n; i++) { t = *start; gmst = XLALGreenwichMeanSiderealTime(XLALGPSAdd(&t, i * deltaT)); if(XLAL_IS_REAL8_FAIL_NAN(gmst)) { XLALDestroyREAL4TimeSeries(*fplus); XLALDestroyREAL4TimeSeries(*fcross); *fplus = *fcross = NULL; XLAL_ERROR(XLAL_EFUNC); } XLALComputeDetAMResponse(&p, &c, D, ra, dec, psi, gmst); (*fplus)->data->data[i] = p; (*fcross)->data->data[i] = c; } return 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()
/** * Computes REAL4TimeSeries containing time series of the full general * metric theory of gravity response amplitudes. * \see XLALComputeDetAMResponseExtraModes() for more details. */ int XLALComputeDetAMResponseExtraModesSeries(REAL4TimeSeries ** fplus, REAL4TimeSeries ** fcross, REAL4TimeSeries ** fb, REAL4TimeSeries ** fl, REAL4TimeSeries ** fx, REAL4TimeSeries ** fy, const REAL4 D[3][3], const double ra, const double dec, const double psi, const LIGOTimeGPS * start, const double deltaT, const int n) { LIGOTimeGPS t; double gmst; int i; double p, c, b, l, x, y; *fplus = XLALCreateREAL4TimeSeries("plus", start, 0.0, deltaT, &lalDimensionlessUnit, n); *fcross = XLALCreateREAL4TimeSeries("cross", start, 0.0, deltaT, &lalDimensionlessUnit, n); *fb = XLALCreateREAL4TimeSeries("b", start, 0.0, deltaT, &lalDimensionlessUnit, n); *fl = XLALCreateREAL4TimeSeries("l", start, 0.0, deltaT, &lalDimensionlessUnit, n); *fx = XLALCreateREAL4TimeSeries("x", start, 0.0, deltaT, &lalDimensionlessUnit, n); *fy = XLALCreateREAL4TimeSeries("y", start, 0.0, deltaT, &lalDimensionlessUnit, n); if(!*fplus || !*fcross || !*fb || !*fl || !*fx || !*fy) { XLALDestroyREAL4TimeSeries(*fplus); XLALDestroyREAL4TimeSeries(*fcross); XLALDestroyREAL4TimeSeries(*fb); XLALDestroyREAL4TimeSeries(*fl); XLALDestroyREAL4TimeSeries(*fx); XLALDestroyREAL4TimeSeries(*fy); *fplus = *fcross = *fb = *fl = *fx = *fy = NULL; XLAL_ERROR(XLAL_EFUNC); } for(i = 0; i < n; i++) { t = *start; gmst = XLALGreenwichMeanSiderealTime(XLALGPSAdd(&t, i * deltaT)); if(XLAL_IS_REAL8_FAIL_NAN(gmst)) { XLALDestroyREAL4TimeSeries(*fplus); XLALDestroyREAL4TimeSeries(*fcross); XLALDestroyREAL4TimeSeries(*fb); XLALDestroyREAL4TimeSeries(*fl); XLALDestroyREAL4TimeSeries(*fx); XLALDestroyREAL4TimeSeries(*fy); *fplus = *fcross = *fb = *fl = *fx = *fy = NULL; XLAL_ERROR(XLAL_EFUNC); } XLALComputeDetAMResponseExtraModes(&p, &c, &b, &l, &x, &y, D, ra, dec, psi, gmst); (*fplus)->data->data[i] = p; (*fcross)->data->data[i] = c; (*fb)->data->data[i] = b; (*fl)->data->data[i] = l; (*fx)->data->data[i] = x; (*fy)->data->data[i] = y; } return 0; }
/** * \author Creighton, T. D. * \brief Computes the next sidereal midnight and autumnal equinox. * * This function takes a GPS time from * <tt>tepoch</tt> and uses it to assign * <tt>tAutumn</tt> and <tt>tMidnight</tt>, which are * REAL8 representations of the time in seconds from * <tt>tepoch</tt> to the next autumnal equinox or sidereal midnight, * respectively. This routine was written under the \ref PulsarTimes_h * module because these quantities are vital for performing pulsar * timing: they characterize the Earth's orbital and rotational phase, * and hence the Doppler modulation on an incoming signal. See * \ref PulsarTimes_h for more information about the * PulsarTimesParamStruc structure. * * ### Algorithm ### * * The routine first computes the Greenwich mean sidereal time at * <tt>tepoch</tt> using XLALGreenwichMeanSiderealTime(). The next sidereal * midnight (at the Prime Meridian) is simply 86400 seconds minus that * sidereal time. * * Next the routine computes the time of the next autumnal equinox. The * module contains an internal list of GPS times of autumnal equinoxes * from 1992 to 2020, given to the nearest minute; this is certainly * enough accuracy for use with the routines in LALTBaryPtolemaic(). * If the specified time <tt>tepoch</tt> is after the 2020 autumnal * equinox, or more than a year before the 1992 equinox, then the next * equinox is extrapolated assuming exact periods of length * \ref LAL_YRSID_SI. * * When assigning the fields of <tt>*times</tt>, it is up to the user to * choose a <tt>tepoch</tt> that is close to the actual times that * are being considered. This is important, since many computations use * a REAL8 time variable whose origin is the time * <tt>tepoch</tt>. If this is too far from the times of interest, * the REAL8 time variables may suffer loss of precision. * * ### Uses ### * * \code * XLALGreenwichMeanSiderealTime() * \endcode */ int XLALGetEarthTimes( const LIGOTimeGPS *tepoch, REAL8 *tMidnight, REAL8 *tAutumn ) { LIGOTimeGPS epoch; /* local copy of times->epoch */ REAL8 t; /* time as a floating-point number (s) */ /* Make sure the parameters exist. */ XLAL_CHECK( tepoch != NULL, XLAL_EFAULT ); XLAL_CHECK( tAutumn != NULL, XLAL_EFAULT ); XLAL_CHECK( tMidnight != NULL, XLAL_EFAULT ); epoch = *tepoch; /* Find the next sidereal midnight. */ t = fmod(XLALGreenwichMeanSiderealTime(&epoch), LAL_TWOPI) * 86400.0 / LAL_TWOPI; XLAL_CHECK( !XLAL_IS_REAL8_FAIL_NAN(t), XLAL_ETIME ); *tMidnight = 86400.0 - t; /* Find the next autumnal equinox. */ while ( epoch.gpsNanoSeconds > 0 ) { epoch.gpsSeconds += 1; epoch.gpsNanoSeconds -= 1000000000; } if ( equinoxes[0] - epoch.gpsSeconds > LAL_YRSID_SI ) { t = (REAL8)( equinoxes[0] - epoch.gpsSeconds ) - (1.0e-9)*epoch.gpsNanoSeconds; *tAutumn = fmod( t, LAL_YRSID_SI ); } else { UINT4 i = 0; /* index over equinox list */ while ( i < NEQUINOXES && equinoxes[i] <= epoch.gpsSeconds ) i++; if ( i == NEQUINOXES ) { t = (REAL8)( equinoxes[i-1] - epoch.gpsSeconds ) - (1.0e-9)*epoch.gpsNanoSeconds; *tAutumn = fmod( t, LAL_YRSID_SI ) + LAL_YRSID_SI; } else *tAutumn = (REAL8)( equinoxes[i] - epoch.gpsSeconds ) - (1.0e-9)*epoch.gpsNanoSeconds; } /* Done. */ return XLAL_SUCCESS; }
/** * Inverse of XLALGreenwichMeanSiderealTime(). The input is sidereal time * in radians since the Julian epoch (currently J2000 for LAL), and the * output is the corresponding GPS time. The algorithm uses a naive * iterative root-finder, so it's slow. */ LIGOTimeGPS *XLALGreenwichMeanSiderealTimeToGPS( REAL8 gmst, LIGOTimeGPS *gps ) { const double gps_seconds_per_sidereal_radian = 13713.44; /* approx */ const double precision = 1e-14; int iterations = 10; double error; XLALGPSSet(gps, 0, 0); do { error = gmst - XLALGreenwichMeanSiderealTime(gps); if(fabs(error / gmst) <= precision) return gps; XLALGPSAdd(gps, error * gps_seconds_per_sidereal_radian); } while(--iterations); XLAL_ERROR_NULL(XLAL_EMAXITER); }
int main( int argc, char *argv[] ) { LALStatus status = blank_status; #if 0 const INT4 S2StartTime = 729273613; /* Feb 14 2003 16:00:00 UTC */ const INT4 S2StopTime = 734367613; /* Apr 14 2003 15:00:00 UTC */ #endif /* command line options */ LIGOTimeGPS gpsStartTime = {S2StartTime, 0}; LIGOTimeGPS gpsEndTime = {S2StopTime, 0}; REAL8 meanTimeStep = 2630 / LAL_PI; REAL8 timeInterval = 0; UINT4 randSeed = 1; CHAR *userTag = NULL; REAL4 minMass = 3.0; /* minimum component mass */ REAL4 maxMass = 20.0; /* maximum component mass */ REAL4 sumMaxMass = 0.0; /* maximum total mass sum */ UINT4 sumMaxMassUse=0; /* flag indicating to use the sumMaxMass */ REAL4 dmin = 1.0; /* minimum distance from earth (kpc) */ REAL4 dmax = 20000.0 ; /* maximum distance from earth (kpc) */ REAL4 fLower = 0; /* default value for th lower cut off frequency */ /* REAL4 Rcore = 0.0; */ UINT4 ddistr = 0, mdistr=0; /* program variables */ RandomParams *randParams = NULL; REAL4 u, exponent, d2; REAL4 deltaM, mtotal; /* waveform */ CHAR waveform[LIGOMETA_WAVEFORM_MAX]; #if 0 int i, stat; double d, cosphi, sinphi; #endif /* GalacticInspiralParamStruc galacticPar; */ /* xml output data */ CHAR fname[256]; MetadataTable proctable; MetadataTable procparams; MetadataTable injections; ProcessParamsTable *this_proc_param; SimInspiralTable *this_inj = NULL; LIGOLwXMLStream xmlfp; UINT4 outCompress = 0; /* getopt arguments */ struct option long_options[] = { {"help", no_argument, 0, 'h'}, {"verbose", no_argument, &vrbflg, 1 }, {"write-compress", no_argument, &outCompress, 1 }, {"version", no_argument, 0, 'V'}, {"f-lower", required_argument, 0, 'f'}, {"gps-start-time", required_argument, 0, 'a'}, {"gps-end-time", required_argument, 0, 'b'}, {"time-step", required_argument, 0, 't'}, {"time-interval", required_argument, 0, 'i'}, {"seed", required_argument, 0, 's'}, {"min-mass", required_argument, 0, 'A'}, {"max-mass", required_argument, 0, 'B'}, {"max-total-mass", required_argument, 0, 'x'}, {"min-distance", required_argument, 0, 'p'}, {"max-distance", required_argument, 0, 'r'}, {"d-distr", required_argument, 0, 'd'}, {"m-distr", required_argument, 0, 'm'}, {"waveform", required_argument, 0, 'w'}, {"user-tag", required_argument, 0, 'Z'}, {"userTag", required_argument, 0, 'Z'}, {0, 0, 0, 0} }; int c; /* set up inital debugging values */ lal_errhandler = LAL_ERR_EXIT; /* create the process and process params tables */ proctable.processTable = (ProcessTable *) calloc( 1, sizeof(ProcessTable) ); XLALGPSTimeNow(&(proctable.processTable->start_time)); if (strcmp(CVS_REVISION,"$Revi" "sion$")) { XLALPopulateProcessTable(proctable.processTable, PROGRAM_NAME, CVS_REVISION, CVS_SOURCE, CVS_DATE, 0); } else { XLALPopulateProcessTable(proctable.processTable, PROGRAM_NAME, lalappsGitCommitID, lalappsGitGitStatus, lalappsGitCommitDate, 0); } snprintf( proctable.processTable->comment, LIGOMETA_COMMENT_MAX, " " ); this_proc_param = procparams.processParamsTable = (ProcessParamsTable *) calloc( 1, sizeof(ProcessParamsTable) ); /* clear the waveform field */ memset( waveform, 0, LIGOMETA_WAVEFORM_MAX * sizeof(CHAR) ); /* * * parse command line arguments * */ while ( 1 ) { /* getopt_long stores long option here */ int option_index = 0; long int gpsinput; size_t optarg_len; c = getopt_long_only( argc, argv, "a:A:b:B:d:f:hi:m:p:q:r:s:t:vZ:w:", long_options, &option_index ); /* detect the end of the options */ if ( c == - 1 ) { break; } switch ( c ) { case 0: /* if this option set a flag, do nothing else now */ if ( long_options[option_index].flag != 0 ) { break; } else { fprintf( stderr, "error parsing option %s with argument %s\n", long_options[option_index].name, optarg ); exit( 1 ); } break; case 'a': gpsinput = atol( optarg ); if ( gpsinput < 441417609 ) { fprintf( stderr, "invalid argument to --%s:\n" "GPS start time is prior to " "Jan 01, 1994 00:00:00 UTC:\n" "(%ld specified)\n", long_options[option_index].name, gpsinput ); exit( 1 ); } gpsStartTime.gpsSeconds = gpsinput; this_proc_param = this_proc_param->next = next_process_param( long_options[option_index].name, "int", "%ld", gpsinput ); break; case 'b': gpsinput = atol( optarg ); if ( gpsinput < 441417609 ) { fprintf( stderr, "invalid argument to --%s:\n" "GPS start time is prior to " "Jan 01, 1994 00:00:00 UTC:\n" "(%ld specified)\n", long_options[option_index].name, gpsinput ); exit( 1 ); } gpsEndTime.gpsSeconds = gpsinput; this_proc_param = this_proc_param->next = next_process_param( long_options[option_index].name, "int", "%ld", gpsinput ); break; case 'f': fLower = atof( optarg ); this_proc_param = this_proc_param->next = next_process_param( long_options[option_index].name, "float", "%f", fLower ); break; case 's': randSeed = atoi( optarg ); this_proc_param = this_proc_param->next = next_process_param( long_options[option_index].name, "int", "%d", randSeed ); break; case 't': meanTimeStep = (REAL8) atof( optarg ); if ( meanTimeStep <= 0 ) { fprintf( stderr, "invalid argument to --%s:\n" "time step must be > 0: (%e seconds specified)\n", long_options[option_index].name, meanTimeStep ); exit( 1 ); } this_proc_param = this_proc_param->next = next_process_param( long_options[option_index].name, "float", "%e", meanTimeStep ); break; case 'i': timeInterval = atof( optarg ); if ( timeInterval < 0 ) { fprintf( stderr, "invalid argument to --%s:\n" "time interval must be >= 0: (%e seconds specified)\n", long_options[option_index].name, meanTimeStep ); exit( 1 ); } this_proc_param = this_proc_param->next = next_process_param( long_options[option_index].name, "float", "%e", timeInterval ); break; case 'A': /* minimum component mass */ minMass = (REAL4) atof( optarg ); if ( minMass <= 0 ) { fprintf( stderr, "invalid argument to --%s:\n" "miniumum component mass must be > 0: " "(%f solar masses specified)\n", long_options[option_index].name, minMass ); exit( 1 ); } this_proc_param = this_proc_param->next = next_process_param( long_options[option_index].name, "float", "%e", minMass ); break; case 'B': /* maximum component mass */ maxMass = (REAL4) atof( optarg ); if ( maxMass <= 0 ) { fprintf( stderr, "invalid argument to --%s:\n" "maxiumum component mass must be > 0: " "(%f solar masses specified)\n", long_options[option_index].name, maxMass ); exit( 1 ); } this_proc_param = this_proc_param->next = next_process_param( long_options[option_index].name, "float", "%e", maxMass ); break; case 'x': /* maximum sum of components */ sumMaxMass = (REAL4) atof( optarg ); if ( sumMaxMass <= 0 ) { fprintf( stderr, "invalid argument to --%s:\n" "sum of two component masses must be > 0: " "(%f solar masses specified)\n", long_options[option_index].name, sumMaxMass ); exit( 1 ); } sumMaxMassUse=1; this_proc_param = this_proc_param->next = next_process_param( long_options[option_index].name, "float", "%e", sumMaxMass ); break; case 'p': /* minimum distance from earth */ dmin = (REAL4) atof( optarg ); if ( dmin <= 0 ) { fprintf( stderr, "invalid argument to --%s:\n" "minimum distance must be > 0: " "(%f kpc specified)\n", long_options[option_index].name, dmin ); exit( 1 ); } this_proc_param = this_proc_param->next = next_process_param( long_options[option_index].name, "float", "%e", dmin ); break; case 'r': /* max distance from earth */ dmax = (REAL4) atof( optarg ); if ( dmax <= 0 ) { fprintf( stderr, "invalid argument to --%s:\n" "maximum distance must be greater than 0: " "(%f kpc specified)\n", long_options[option_index].name, dmax ); exit( 1 ); } this_proc_param = this_proc_param->next = next_process_param( long_options[option_index].name, "float", "%e", dmax ); break; case 'd': ddistr = (UINT4) atoi( optarg ); if ( ddistr != 0 && ddistr != 1 && ddistr != 2) { fprintf( stderr, "invalid argument to --%s:\n" "DDISTR must be either 0 or 1 or 2\n", long_options[option_index].name); exit(1); } this_proc_param = this_proc_param->next = next_process_param( long_options[option_index].name, "int", "%d", ddistr ); break; case 'm': mdistr = (UINT4) atoi( optarg ); if ( mdistr != 0 && mdistr != 1 ) { fprintf( stderr, "invalid argument to --%s:\n" "MDISTR must be either 0 or 1\n", long_options[option_index].name); exit(1); } this_proc_param = this_proc_param->next = next_process_param( long_options[option_index].name, "int", "%d", mdistr ); break; case 'Z': /* create storage for the usertag */ optarg_len = strlen( optarg ) + 1; userTag = (CHAR *) calloc( optarg_len, sizeof(CHAR) ); memcpy( userTag, optarg, optarg_len ); this_proc_param = this_proc_param->next = next_process_param( long_options[option_index].name, "string", "%s", optarg ); break; case 'w': snprintf( waveform, LIGOMETA_WAVEFORM_MAX, "%s", optarg); this_proc_param = this_proc_param->next = next_process_param( long_options[option_index].name, "string", "%s", optarg); break; case 'V': /* print version information and exit */ fprintf( stdout, "Binary Black Hole INJection generation routine\n" "Duncan A Brown and Eirini Messaritaki\n" "CVS Version: " CVS_ID_STRING "\n" "CVS Tag: " CVS_NAME_STRING "\n" ); fprintf( stdout, lalappsGitID ); exit( 0 ); break; case 'h': case '?': fprintf( stderr, USAGE ); exit( 0 ); break; default: fprintf( stderr, "unknown error while parsing options\n" ); fprintf( stderr, USAGE ); exit( 1 ); } } if ( optind < argc ) { fprintf( stderr, "extraneous command line arguments:\n" ); while ( optind < argc ) { fprintf ( stderr, "%s\n", argv[optind++] ); } exit( 1 ); } if ( !*waveform ) { /* use EOBtwoPN as the default waveform */ snprintf( waveform, LIGOMETA_WAVEFORM_MAX, "EOBtwoPN"); } if ( !fLower ) { fprintf( stderr, "--f-lower must be specified and non-zero\n" ); exit( 1 ); } /* * * initialization * */ /* initialize the random number generator */ LAL_CALL( LALCreateRandomParams( &status, &randParams, randSeed ), &status ); /* mass range, per component */ deltaM = maxMass - minMass; /* null out the head of the linked list */ injections.simInspiralTable = NULL; /* create the output file name */ if ( userTag && outCompress ) { snprintf( fname, sizeof(fname), "HL-INJECTIONS_%d_%s-%d-%d.xml.gz", randSeed, userTag, gpsStartTime.gpsSeconds, gpsEndTime.gpsSeconds - gpsStartTime.gpsSeconds ); } else if ( userTag && !outCompress ) { snprintf( fname, sizeof(fname), "HL-INJECTIONS_%d_%s-%d-%d.xml", randSeed, userTag, gpsStartTime.gpsSeconds, gpsEndTime.gpsSeconds - gpsStartTime.gpsSeconds ); } else if ( !userTag && outCompress ) { snprintf( fname, sizeof(fname), "HL-INJECTIONS_%d-%d-%d.xml.gz", randSeed, gpsStartTime.gpsSeconds, gpsEndTime.gpsSeconds - gpsStartTime.gpsSeconds ); } else { snprintf( fname, sizeof(fname), "HL-INJECTIONS_%d-%d-%d.xml", randSeed, gpsStartTime.gpsSeconds, gpsEndTime.gpsSeconds - gpsStartTime.gpsSeconds ); } /* * * loop over duration of desired output times * */ while ( XLALGPSCmp( &gpsStartTime, &gpsEndTime ) < 0 ) { /* rho, z and lGal are the galactocentric galactic axial coordinates */ /* r and phi are the geocentric galactic spherical coordinates */ #if 0 LAL_CALL( LALUniformDeviate( &status, &u, randParams ), &status ); galacticPar.lGal = LAL_TWOPI * u; galacticPar.z = r * sinphi ; galacticPar.rho = 0.0 - Rcore * cos(galacticPar.lGal) + sqrt( r * r - galacticPar.z * galacticPar.z - Rcore * Rcore * sin(galacticPar.lGal) * sin(galacticPar.lGal) ); #endif #if 0 if ( vrbflg ) fprintf( stdout, "%e %e %e %e %e\n", galacticPar.m1, galacticPar.m2, galacticPar.rho * cos( galacticPar.lGal ), galacticPar.rho * sin( galacticPar.lGal ), galacticPar.z ); #endif /* create the sim_inspiral table */ if ( injections.simInspiralTable ) { this_inj = this_inj->next = (SimInspiralTable *) LALCalloc( 1, sizeof(SimInspiralTable) ); } else { injections.simInspiralTable = this_inj = (SimInspiralTable *) LALCalloc( 1, sizeof(SimInspiralTable) ); } /* set the geocentric end time of the injection */ /* XXX CHECK XXX */ this_inj->geocent_end_time = gpsStartTime; if ( timeInterval ) { LAL_CALL( LALUniformDeviate( &status, &u, randParams ), &status ); XLALGPSAdd( &(this_inj->geocent_end_time), u * timeInterval ); } /* set gmst */ this_inj->end_time_gmst = fmod(XLALGreenwichMeanSiderealTime( &this_inj->geocent_end_time), LAL_TWOPI) * 24.0 / LAL_TWOPI; /* hours */ if( XLAL_IS_REAL8_FAIL_NAN(this_inj->end_time_gmst) ) { fprintf(stderr, "XLALGreenwichMeanSiderealTime() failed\n"); exit(1); } /* XXX END CHECK XXX */ /* populate the sim_inspiral table */ if (mdistr == 1) /* uniformly distributed mass1 and uniformly distributed mass2 */ { LAL_CALL( LALUniformDeviate( &status, &u, randParams ), &status ); this_inj->mass1 = minMass + u * deltaM; LAL_CALL( LALUniformDeviate( &status, &u, randParams ), &status ); this_inj->mass2 = minMass + u * deltaM; mtotal = this_inj->mass1 + this_inj->mass2 ; this_inj->eta = this_inj->mass1 * this_inj->mass2 / ( mtotal * mtotal ); this_inj->mchirp = (this_inj->mass1 + this_inj->mass2) * pow(this_inj->eta, 0.6); } else if (mdistr == 0) /*uniformly distributed total mass */ { LAL_CALL( LALUniformDeviate( &status, &u, randParams ), &status); mtotal = 2.0 * minMass + u * 2.0 *deltaM ; if (sumMaxMassUse==1) { while (mtotal > sumMaxMass) { LAL_CALL( LALUniformDeviate( &status, &u, randParams ), &status); mtotal = 2.0 * minMass + u * 2.0 *deltaM ; } } LAL_CALL( LALUniformDeviate( &status, &u, randParams ), &status ); this_inj->mass1 = minMass + u * deltaM; this_inj->mass2 = mtotal - this_inj->mass1; while (this_inj->mass1 >= mtotal || this_inj->mass2 >= maxMass || this_inj->mass2 <= minMass ) { LAL_CALL( LALUniformDeviate( &status, &u, randParams ), &status ); this_inj->mass1 = minMass + u * deltaM; this_inj->mass2 = mtotal - this_inj->mass1; } this_inj->eta = this_inj->mass1 * this_inj->mass2 / ( mtotal * mtotal ); this_inj->mchirp = (this_inj->mass1 + this_inj->mass2) * pow(this_inj->eta, 0.6); } /* spatial distribution */ #if 0 LAL_CALL( LALUniformDeviate( &status, &u, randParams ), &status ); sinphi = 2.0 * u - 1.0; cosphi = sqrt( 1.0 - sinphi*sinphi ); #endif if (ddistr == 0) /* uniform distribution in distance */ { REAL4 deltaD = dmax - dmin ; LAL_CALL( LALUniformDeviate( &status, &u, randParams ), &status ); this_inj->distance = dmin + deltaD * u ; } else if (ddistr == 1) /* uniform distribution in log(distance) */ { REAL4 lmin = log10(dmin); REAL4 lmax = log10(dmax); REAL4 deltaL = lmax - lmin; LAL_CALL( LALUniformDeviate(&status,&u,randParams),&status ); exponent = lmin + deltaL * u; this_inj->distance = pow(10.0,(REAL4) exponent); } else if (ddistr == 2) /* uniform volume distribution */ { REAL4 d2min = pow(dmin,3.0) ; REAL4 d2max = pow(dmax,3.0) ; REAL4 deltad2 = d2max - d2min ; LAL_CALL( LALUniformDeviate(&status,&u,randParams),&status ); d2 = d2min + u * deltad2 ; this_inj->distance = pow(d2,1.0/3.0); } this_inj->distance = this_inj->distance / 1000.0; /*convert to Mpc */ /* compute random longitude and latitude */ LAL_CALL( LALUniformDeviate( &status, &u, randParams ), &status ); this_inj->latitude = asin( 2.0 * u - 1.0 ) ; LAL_CALL( LALUniformDeviate( &status, &u, randParams ), &status ); this_inj->longitude = LAL_TWOPI * u ; #if 0 LAL_CALL( LALGalacticInspiralParamsToSimInspiralTable( &status, this_inj, &galacticPar, randParams ), &status ); if (vrbflg) { fprintf( stdout, "%e\n", sqrt(galacticPar.z*galacticPar.z+galacticPar.rho*galacticPar.rho + Rcore*Rcore + 2.0*Rcore*galacticPar.rho*cos(galacticPar.lGal))- this_inj->distance*1000.0); } #endif /* set the source and waveform fields */ snprintf( this_inj->source, LIGOMETA_SOURCE_MAX, "???" ); memcpy( this_inj->waveform, waveform, LIGOMETA_WAVEFORM_MAX * sizeof(CHAR)); /* XXX CHECK XXX */ /* compute random inclination, polarization and coalescence phase */ LAL_CALL( LALUniformDeviate( &status, &u, randParams ), &status ); this_inj->inclination = acos( 2.0 * u - 1.0 ); LAL_CALL( LALUniformDeviate( &status, &u, randParams ), &status ); this_inj->polarization = LAL_TWOPI * u ; LAL_CALL( LALUniformDeviate( &status, &u, randParams ), &status ); this_inj->coa_phase = LAL_TWOPI * u ; /* populate the site specific information */ LAL_CALL(LALPopulateSimInspiralSiteInfo( &status, this_inj ), &status); /* increment the injection time */ XLALGPSAdd( &gpsStartTime, meanTimeStep ); /* finally populate the flower */ if (fLower > 0) { this_inj->f_lower = fLower; } else { this_inj->f_lower = 0; } /* XXX END CHECK XXX */ } /* end loop over injection times */ /* destroy random parameters */ LAL_CALL( LALDestroyRandomParams( &status, &randParams ), &status ); /* * * write output to LIGO_LW XML file * */ /* open the xml file */ memset( &xmlfp, 0, sizeof(LIGOLwXMLStream) ); LAL_CALL( LALOpenLIGOLwXMLFile( &status, &xmlfp, fname ), &status ); /* write the process table */ snprintf( proctable.processTable->ifos, LIGOMETA_IFOS_MAX, "H1H2L1" ); XLALGPSTimeNow(&(proctable.processTable->end_time)); LAL_CALL( LALBeginLIGOLwXMLTable( &status, &xmlfp, process_table ), &status ); LAL_CALL( LALWriteLIGOLwXMLTable( &status, &xmlfp, proctable, process_table ), &status ); LAL_CALL( LALEndLIGOLwXMLTable ( &status, &xmlfp ), &status ); free( proctable.processTable ); /* free the unused process param entry */ this_proc_param = procparams.processParamsTable; procparams.processParamsTable = procparams.processParamsTable->next; free( this_proc_param ); /* write the process params table */ if ( procparams.processParamsTable ) { LAL_CALL( LALBeginLIGOLwXMLTable( &status, &xmlfp, process_params_table ), &status ); LAL_CALL( LALWriteLIGOLwXMLTable( &status, &xmlfp, procparams, process_params_table ), &status ); LAL_CALL( LALEndLIGOLwXMLTable ( &status, &xmlfp ), &status ); while( procparams.processParamsTable ) { this_proc_param = procparams.processParamsTable; procparams.processParamsTable = this_proc_param->next; free( this_proc_param ); } } /* write the sim_inspiral table */ if ( injections.simInspiralTable ) { LAL_CALL( LALBeginLIGOLwXMLTable( &status, &xmlfp, sim_inspiral_table ), &status ); LAL_CALL( LALWriteLIGOLwXMLTable( &status, &xmlfp, injections, sim_inspiral_table ), &status ); LAL_CALL( LALEndLIGOLwXMLTable ( &status, &xmlfp ), &status ); } while ( injections.simInspiralTable ) { this_inj = injections.simInspiralTable; injections.simInspiralTable = injections.simInspiralTable->next; LALFree( this_inj ); } /* close the injection file */ LAL_CALL( LALCloseLIGOLwXMLFile ( &status, &xmlfp ), &status ); /* check for memory leaks and exit */ LALCheckMemoryLeaks(); return 0; }
REAL8 calculate_lalsim_snr(SimInspiralTable *inj, char *IFOname, REAL8FrequencySeries *psd, REAL8 start_freq) { /* Calculate and return the single IFO SNR * * Required options: * * inj: SimInspiralTable entry for which the SNR has to be calculated * IFOname: The canonical name (e.g. H1, L1, V1) name of the IFO for which the SNR must be calculated * PSD: PSD curve to be used for the overlap integrap * start_freq: lower cutoff of the overlap integral * * */ int ret=0; INT4 errnum=0; UINT4 j=0; /* Fill detector site info */ LALDetector* detector=NULL; detector=calloc(1,sizeof(LALDetector)); if(!strcmp(IFOname,"H1")) memcpy(detector,&lalCachedDetectors[LALDetectorIndexLHODIFF],sizeof(LALDetector)); if(!strcmp(IFOname,"H2")) memcpy(detector,&lalCachedDetectors[LALDetectorIndexLHODIFF],sizeof(LALDetector)); if(!strcmp(IFOname,"LLO")||!strcmp(IFOname,"L1")) memcpy(detector,&lalCachedDetectors[LALDetectorIndexLLODIFF],sizeof(LALDetector)); if(!strcmp(IFOname,"V1")||!strcmp(IFOname,"VIRGO")) memcpy(detector,&lalCachedDetectors[LALDetectorIndexVIRGODIFF],sizeof(LALDetector)); Approximant approx=TaylorF2; approx=XLALGetApproximantFromString(inj->waveform); LALSimulationDomain modelDomain; if(XLALSimInspiralImplementedFDApproximants(approx)) modelDomain = LAL_SIM_DOMAIN_FREQUENCY; else if(XLALSimInspiralImplementedTDApproximants(approx)) modelDomain = LAL_SIM_DOMAIN_TIME; else { fprintf(stderr,"ERROR. Unknown approximant number %i. Unable to choose time or frequency domain model.",approx); exit(1); } REAL8 m1,m2, s1x,s1y,s1z,s2x,s2y,s2z,phi0,f_min,f_max,iota,polarization; /* No tidal PN terms until injtable is able to get them */ LALDict *LALpars= XLALCreateDict(); /* Spin and tidal interactions at the highest level (default) until injtable stores them. * When spinO and tideO are added to injtable we can un-comment those lines and should be ok * int spinO = inj->spinO; int tideO = inj->tideO; XLALSimInspiralSetSpinOrder(waveFlags, *(LALSimInspiralSpinOrder*) spinO); XLALSimInspiralSetTidalOrder(waveFlags, *(LALSimInspiralTidalOrder*) tideO); */ XLALSimInspiralWaveformParamsInsertPNPhaseOrder(LALpars,XLALGetOrderFromString(inj->waveform)); XLALSimInspiralWaveformParamsInsertPNAmplitudeOrder(LALpars,inj->amp_order); /* Read parameters */ m1=inj->mass1*LAL_MSUN_SI; m2=inj->mass2*LAL_MSUN_SI; s1x=inj->spin1x; s1y=inj->spin1y; s1z=inj->spin1z; s2x=inj->spin2x; s2y=inj->spin2y; s2z=inj->spin2z; iota=inj->inclination; f_min=XLALSimInspiralfLow2fStart(inj->f_lower,XLALSimInspiralWaveformParamsLookupPNAmplitudeOrder(LALpars),XLALGetApproximantFromString(inj->waveform)); phi0=inj->coa_phase; polarization=inj->polarization; REAL8 latitude=inj->latitude; REAL8 longitude=inj->longitude; LIGOTimeGPS epoch; memcpy(&epoch,&(inj->geocent_end_time),sizeof(LIGOTimeGPS)); /* Hardcoded values of srate and segment length. If changed here they must also be changed in inspinj.c */ REAL8 srate=4096.0; const CHAR *WF=inj->waveform; /* Increase srate for EOB WFs */ if (strstr(WF,"EOB")) srate=8192.0; REAL8 segment=64.0; f_max=(srate/2.0-(1.0/segment)); size_t seglen=(size_t) segment*srate; REAL8 deltaF=1.0/segment; REAL8 deltaT=1.0/srate; /* Frequency domain h+ and hx. They are going to be filled either by a FD WF or by the FFT of a TD WF*/ COMPLEX16FrequencySeries *freqHplus; COMPLEX16FrequencySeries *freqHcross; freqHplus= XLALCreateCOMPLEX16FrequencySeries("fhplus", &epoch, 0.0, deltaF, &lalDimensionlessUnit, seglen/2+1 ); freqHcross=XLALCreateCOMPLEX16FrequencySeries("fhcross", &epoch, 0.0, deltaF, &lalDimensionlessUnit, seglen/2+1 ); /* If the approximant is on the FD call XLALSimInspiralChooseFDWaveform */ if (modelDomain == LAL_SIM_DOMAIN_FREQUENCY) { COMPLEX16FrequencySeries *hptilde=NULL; COMPLEX16FrequencySeries *hctilde=NULL; //We do not pass the polarization here, we assume it is taken into account when projecting h+,x onto the detector. XLAL_TRY(ret=XLALSimInspiralChooseFDWaveform(&hptilde,&hctilde, m1, m2, s1x, s1y, s1z, s2x, s2y, s2z, LAL_PC_SI * 1.0e6, iota, phi0, 0., 0., 0., deltaF, f_min, 0.0, 0.0, LALpars,approx),errnum); XLALDestroyDict(LALpars); if(!hptilde|| hptilde->data==NULL || hptilde->data->data==NULL ||!hctilde|| hctilde->data==NULL || hctilde->data->data==NULL) { XLALPrintError(" ERROR in XLALSimInspiralChooseFDWaveform(): error generating waveform. errnum=%d. Exiting...\n",errnum ); exit(1); } COMPLEX16 *dataPtr = hptilde->data->data; for (j=0; j<(UINT4) freqHplus->data->length; ++j) { if(j < hptilde->data->length) { freqHplus->data->data[j] = dataPtr[j]; } else { freqHplus->data->data[j]=0.0 + I*0.0; } } dataPtr = hctilde->data->data; for (j=0; j<(UINT4) freqHplus->data->length; ++j) { if(j < hctilde->data->length) { freqHcross->data->data[j] = dataPtr[j]; } else { freqHcross->data->data[j]=0.0+0.0*I; } } /* Clean */ if(hptilde) XLALDestroyCOMPLEX16FrequencySeries(hptilde); if(hctilde) XLALDestroyCOMPLEX16FrequencySeries(hctilde); } else { /* Otherwise use XLALSimInspiralChooseTDWaveform */ REAL8FFTPlan *timeToFreqFFTPlan = XLALCreateForwardREAL8FFTPlan((UINT4) seglen, 0 ); REAL8TimeSeries *hplus=NULL; REAL8TimeSeries *hcross=NULL; REAL8TimeSeries *timeHplus=NULL; REAL8TimeSeries *timeHcross=NULL; REAL8 padding =0.4;//seconds REAL8Window *window=XLALCreateTukeyREAL8Window(seglen,(REAL8)2.0*padding*srate/(REAL8)seglen); REAL4 WinNorm = sqrt(window->sumofsquares/window->data->length); timeHcross=XLALCreateREAL8TimeSeries("timeModelhCross", &epoch, 0.0, deltaT, &lalStrainUnit, seglen ); timeHplus=XLALCreateREAL8TimeSeries("timeModelhplus", &epoch, 0.0, deltaT, &lalStrainUnit, seglen ); for (j=0;j<(UINT4) timeHcross->data->length;++j) timeHcross->data->data[j]=0.0; for (j=0;j<(UINT4) timeHplus->data->length;++j) timeHplus->data->data[j]=0.0; XLAL_TRY(ret=XLALSimInspiralChooseTDWaveform(&hplus, &hcross, m1, m2, s1x, s1y, s1z, s2x, s2y, s2z, LAL_PC_SI*1.0e6, iota, phi0, 0., 0., 0., deltaT, f_min, 0., LALpars, approx), errnum); if (ret == XLAL_FAILURE || hplus == NULL || hcross == NULL) { XLALPrintError(" ERROR in XLALSimInspiralChooseTDWaveform(): error generating waveform. errnum=%d. Exiting...\n",errnum ); exit(1); } hplus->epoch = timeHplus->epoch; hcross->epoch = timeHcross->epoch; XLALSimAddInjectionREAL8TimeSeries(timeHplus, hplus, NULL); XLALSimAddInjectionREAL8TimeSeries(timeHcross, hcross, NULL); for (j=0; j<(UINT4) timeHplus->data->length; ++j) timeHplus->data->data[j]*=window->data->data[j]; for (j=0; j<(UINT4) timeHcross->data->length; ++j) timeHcross->data->data[j]*=window->data->data[j]; for (j=0; j<(UINT4) freqHplus->data->length; ++j) { freqHplus->data->data[j]=0.0+I*0.0; freqHcross->data->data[j]=0.0+I*0.0; } /* FFT into freqHplus and freqHcross */ XLALREAL8TimeFreqFFT(freqHplus,timeHplus,timeToFreqFFTPlan); XLALREAL8TimeFreqFFT(freqHcross,timeHcross,timeToFreqFFTPlan); for (j=0; j<(UINT4) freqHplus->data->length; ++j) { freqHplus->data->data[j]/=WinNorm; freqHcross->data->data[j]/=WinNorm; } /* Clean... */ if ( hplus ) XLALDestroyREAL8TimeSeries(hplus); if ( hcross ) XLALDestroyREAL8TimeSeries(hcross); if ( timeHplus ) XLALDestroyREAL8TimeSeries(timeHplus); if ( timeHcross ) XLALDestroyREAL8TimeSeries(timeHcross); if (timeToFreqFFTPlan) LALFree(timeToFreqFFTPlan); if (window) XLALDestroyREAL8Window(window); } /* The WF has been generated and is in freqHplus/cross. Now project into the IFO frame */ double Fplus, Fcross; double FplusScaled, FcrossScaled; double HSquared; double GPSdouble=(REAL8) inj->geocent_end_time.gpsSeconds+ (REAL8) inj->geocent_end_time.gpsNanoSeconds*1.0e-9; double gmst; LIGOTimeGPS GPSlal; XLALGPSSetREAL8(&GPSlal, GPSdouble); gmst=XLALGreenwichMeanSiderealTime(&GPSlal); /* Fill Fplus and Fcross*/ XLALComputeDetAMResponse(&Fplus, &Fcross, (const REAL4 (*)[3])detector->response,longitude, latitude, polarization, gmst); /* And take the distance into account */ FplusScaled = Fplus / (inj->distance); FcrossScaled = Fcross / (inj->distance); REAL8 timedelay = XLALTimeDelayFromEarthCenter(detector->location,longitude, latitude, &GPSlal); REAL8 timeshift = timedelay; REAL8 twopit = LAL_TWOPI * timeshift; UINT4 lower = (UINT4)ceil(start_freq / deltaF); UINT4 upper = (UINT4)floor(f_max / deltaF); REAL8 re = cos(twopit*deltaF*lower); REAL8 im = -sin(twopit*deltaF*lower); /* Incremental values, using cos(theta) - 1 = -2*sin(theta/2)^2 */ REAL8 dim = -sin(twopit*deltaF); REAL8 dre = -2.0*sin(0.5*twopit*deltaF)*sin(0.5*twopit*deltaF); REAL8 TwoDeltaToverN = 2.0 *deltaT / ((double) seglen); REAL8 plainTemplateReal, plainTemplateImag,templateReal,templateImag; REAL8 newRe, newIm,temp; REAL8 this_snr=0.0; if ( psd ) { psd = XLALInterpolatePSD(psd, deltaF); } for (j=lower; j<=(UINT4) upper; ++j) { /* derive template (involving location/orientation parameters) from given plus/cross waveforms: */ plainTemplateReal = FplusScaled * creal(freqHplus->data->data[j]) + FcrossScaled *creal(freqHcross->data->data[j]); plainTemplateImag = FplusScaled * cimag(freqHplus->data->data[j]) + FcrossScaled * cimag(freqHcross->data->data[j]); /* do time-shifting... */ /* (also un-do 1/deltaT scaling): */ templateReal = (plainTemplateReal*re - plainTemplateImag*im) / deltaT; templateImag = (plainTemplateReal*im + plainTemplateImag*re) / deltaT; HSquared = templateReal*templateReal + templateImag*templateImag ; temp = ((TwoDeltaToverN * HSquared) / psd->data->data[j]); this_snr += temp; /* Now update re and im for the next iteration. */ newRe = re + re*dre - im*dim; newIm = im + re*dim + im*dre; re = newRe; im = newIm; } /* Clean */ if (freqHcross) XLALDestroyCOMPLEX16FrequencySeries(freqHcross); if (freqHplus) XLALDestroyCOMPLEX16FrequencySeries(freqHplus); if (detector) free(detector); return sqrt(this_snr*2.0); }
void LALGalacticInspiralParamsToSimInspiralTable( LALStatus *status, SimInspiralTable *output, GalacticInspiralParamStruc *input, RandomParams *params ) { PPNParamStruc ppnParams; SkyPosition skyPos; LALSource source; LALDetector lho = lalCachedDetectors[LALDetectorIndexLHODIFF]; LALDetector llo = lalCachedDetectors[LALDetectorIndexLLODIFF]; LALDetAndSource detAndSource; LALDetAMResponse resp; REAL8 time_diff; REAL4 splus, scross, cosiota; INITSTATUS(status); ATTATCHSTATUSPTR( status ); ASSERT( output, status, LIGOMETADATAUTILSH_ENULL, LIGOMETADATAUTILSH_MSGENULL ); ASSERT( input, status, LIGOMETADATAUTILSH_ENULL, LIGOMETADATAUTILSH_MSGENULL ); ASSERT( params, status, LIGOMETADATAUTILSH_ENULL, LIGOMETADATAUTILSH_MSGENULL ); /* * * compute sky position and inspiral params * */ /* generate the ppn inspiral params */ memset( &ppnParams, 0, sizeof(PPNParamStruc) ); LALGetInspiralParams( status->statusPtr, &ppnParams, input, params ); CHECKSTATUSPTR( status ); if ( ppnParams.position.system != COORDINATESYSTEM_EQUATORIAL ) { ABORT( status, LIGOMETADATAUTILSH_ECOOR, LIGOMETADATAUTILSH_MSGECOOR ); } /* copy the inspiral data into sim_inspiral table */ output->mass1 = input->m1; output->mass2 = input->m2; output->eta = ppnParams.eta; output->distance = ppnParams.d / (1.0e6 * LAL_PC_SI); /* Mpc */ output->longitude = ppnParams.position.longitude; output->latitude = ppnParams.position.latitude; output->inclination = ppnParams.inc; output->coa_phase = ppnParams.phi; output->polarization = ppnParams.psi; /* populate geocentric end time */ output->geocent_end_time = input->geocentEndTime; /* populate gmst field (hours) */ output->end_time_gmst = fmod(XLALGreenwichMeanSiderealTime( &output->geocent_end_time), LAL_TWOPI) * 24.0 / LAL_TWOPI; /* hours*/ ASSERT( !XLAL_IS_REAL8_FAIL_NAN(output->end_time_gmst), status, LAL_FAIL_ERR, LAL_FAIL_MSG ); /* set up params for the site end times and detector response */ memset( &skyPos, 0, sizeof(SkyPosition) ); memset( &source, 0, sizeof(LALSource) ); memset( &detAndSource, 0, sizeof(LALDetAndSource) ); skyPos.longitude = output->longitude; skyPos.latitude = output->latitude; skyPos.system = COORDINATESYSTEM_EQUATORIAL; source.equatorialCoords = skyPos; source.orientation = output->polarization; detAndSource.pSource = &source; /* * * compute site end times * */ /* initialize end times with geocentric value */ output->h_end_time = output->l_end_time = input->geocentEndTime; /* ligo hanford observatory */ time_diff = XLALTimeDelayFromEarthCenter( lho.location, skyPos.longitude, skyPos.latitude, &(output->geocent_end_time) ); XLALGPSAdd(&(output->h_end_time), time_diff); /* ligo livingston observatory */ time_diff = XLALTimeDelayFromEarthCenter( llo.location, skyPos.longitude, skyPos.latitude, &(output->geocent_end_time) ); XLALGPSAdd(&(output->l_end_time), time_diff); /* * * compute the effective distance of the inspiral * */ /* initialize distances with real distance and compute splus and scross */ output->eff_dist_h = output->eff_dist_l = 2.0 * output->distance; cosiota = cos( output->inclination ); splus = -( 1.0 + cosiota * cosiota ); scross = -2.0 * cosiota; /* compute the response of the LHO detectors */ detAndSource.pDetector = &lho; LALComputeDetAMResponse( status->statusPtr, &resp, &detAndSource, &output->geocent_end_time ); CHECKSTATUSPTR( status ); /* compute the effective distance for LHO */ output->eff_dist_h /= sqrt( splus*splus*resp.plus*resp.plus + scross*scross*resp.cross*resp.cross ); /* compute the response of the LLO detector */ detAndSource.pDetector = &llo; LALComputeDetAMResponse( status->statusPtr, &resp, &detAndSource, &output->geocent_end_time ); CHECKSTATUSPTR( status ); /* compute the effective distance for LLO */ output->eff_dist_l /= sqrt( splus*splus*resp.plus*resp.plus + scross*scross*resp.cross*resp.cross ); /* * * normal exit * */ DETATCHSTATUSPTR (status); RETURN (status); }
void LALFindChirpBCVCFilterSegment ( LALStatus *status, SnglInspiralTable **eventList, FindChirpFilterInput *input, FindChirpFilterParams *params ) { UINT4 j, k, kFinal/*, kOpt*/; UINT4 numPoints; UINT4 deltaEventIndex = 0; UINT4 ignoreIndex; REAL4 UNUSED myfmin; REAL4 deltaT, deltaF; REAL4 norm; REAL4 modqsqThresh; REAL4 rhosqThresh; REAL4 mismatch; REAL4 UNUSED chisqThreshFac = 0; /* REAL4 modChisqThresh; */ UINT4 numChisqBins = 0; UINT4 eventStartIdx = 0; UINT4 UNUSED *chisqBin = NULL; UINT4 UNUSED *chisqBinBCV = NULL; REAL4 chirpTime = 0; REAL4 UNUSED *tmpltPower = NULL; REAL4 UNUSED *tmpltPowerBCV = NULL; COMPLEX8 *qtilde = NULL; COMPLEX8 *qtildeBCV = NULL; COMPLEX8 *q = NULL; COMPLEX8 *qBCV = NULL; COMPLEX8 *inputData = NULL; COMPLEX8 *inputDataBCV = NULL; COMPLEX8 *tmpltSignal = NULL; SnglInspiralTable *thisEvent = NULL; REAL4 a1 = 0.0; REAL4 b1 = 0.0; REAL4 b2 = 0.0; REAL4 UNUSED templateNorm; REAL4 m, psi0, psi3, fFinal; /* some declarations for the constrained BCV codet (Thomas)*/ REAL4 alphaUnity; /* intermediate variable to get thetab */ REAL4 thetab; /* critical angle for constraint */ REAL4 thetav; /* angle between V1 and V2 */ REAL4 V0; /* intermediate quantity to compute rho */ REAL4 V1; /* intermediate quantity to compute rho */ REAL4 V2; /* intermediate quantity to compute rho */ REAL4 alphaC; /* constraint alpha value */ REAL4 alphaU; /* unconstraint alpha value for fun */ REAL4 rhosqConstraint; REAL4 rhosqUnconstraint; /* before constraint */ REAL4 deltaTPower2By3; /* alias variable */ REAL4 deltaTPower1By6; /* alias variable */ REAL4 ThreeByFive = 3.0/5.0; REAL4 FiveByThree = 5.0/3.0; REAL4 mchirp; REAL4 eta; REAL4 SQRTNormA1; /* an alias */ /* Most of the code below is identical and should be identical to * FindChirpBCVFilter.c execpt when entering the constraint code. * */ INITSTATUS(status); ATTATCHSTATUSPTR( status ); /* * * check that the arguments are reasonable * */ /* make sure the output handle exists, but points to a null pointer */ ASSERT( eventList, status, FINDCHIRPH_ENULL, FINDCHIRPH_MSGENULL ); ASSERT( !*eventList, status, FINDCHIRPH_ENNUL, FINDCHIRPH_MSGENNUL ); /* make sure that the parameter structure exists */ ASSERT( params, status, FINDCHIRPH_ENULL, FINDCHIRPH_MSGENULL ); /* check that the filter parameters are reasonable */ ASSERT( params->deltaT > 0, status, FINDCHIRPH_EDTZO, FINDCHIRPH_MSGEDTZO ); ASSERT( params->rhosqThresh >= 0, status, FINDCHIRPH_ERHOT, FINDCHIRPH_MSGERHOT ); ASSERT( params->chisqThresh >= 0, status, FINDCHIRPH_ECHIT, FINDCHIRPH_MSGECHIT ); /* check that the fft plan exists */ ASSERT( params->invPlan, status, FINDCHIRPH_ENULL, FINDCHIRPH_MSGENULL ); /* check that the workspace vectors exist */ ASSERT(params->qVec, status, FINDCHIRPH_ENULL, FINDCHIRPH_MSGENULL ); ASSERT(params->qVec->data, status, FINDCHIRPH_ENULL, FINDCHIRPH_MSGENULL ); ASSERT(params->qtildeVec, status, FINDCHIRPH_ENULL, FINDCHIRPH_MSGENULL ); ASSERT(params->qtildeVec->data,status, FINDCHIRPH_ENULL, FINDCHIRPH_MSGENULL); ASSERT(params->qVecBCV, status, FINDCHIRPH_ENULL, FINDCHIRPH_MSGENULL ); ASSERT(params->qVecBCV->data, status, FINDCHIRPH_ENULL, FINDCHIRPH_MSGENULL ); ASSERT(params->qtildeVecBCV, status, FINDCHIRPH_ENULL, FINDCHIRPH_MSGENULL ); ASSERT(params->qtildeVecBCV->data,status, FINDCHIRPH_ENULL, FINDCHIRPH_MSGENULL); /* check that the chisq parameter and input structures exist */ ASSERT( params->chisqParams, status, FINDCHIRPH_ENULL, FINDCHIRPH_MSGENULL ); ASSERT( params->chisqInput, status, FINDCHIRPH_ENULL, FINDCHIRPH_MSGENULL ); ASSERT( params->chisqInputBCV,status, FINDCHIRPH_ENULL, FINDCHIRPH_MSGENULL ); /* if a rhosqVec vector has been created, check we can store data in it */ if ( params->rhosqVec ) { ASSERT( params->rhosqVec->data->data, status, FINDCHIRPH_ENULL, FINDCHIRPH_MSGENULL ); ASSERT( params->rhosqVec->data, status, FINDCHIRPH_ENULL, FINDCHIRPH_MSGENULL ); } /* if a chisqVec vector has been created, check we can store data in it */ if ( params->chisqVec ) { ASSERT( params->chisqVec->data, status, FINDCHIRPH_ENULL, FINDCHIRPH_MSGENULL ); } /* make sure that the input structure exists */ ASSERT( input, status, FINDCHIRPH_ENULL, FINDCHIRPH_MSGENULL ); /* make sure that the input structure contains some input */ ASSERT( input->fcTmplt, status, FINDCHIRPH_ENULL, FINDCHIRPH_MSGENULL ); ASSERT( input->segment, status, FINDCHIRPH_ENULL, FINDCHIRPH_MSGENULL ); /* make sure the filter has been initialized for the correct approximant */ if ( params->approximant != BCV ) { ABORT( status, FINDCHIRPH_EAPRX, FINDCHIRPH_MSGEAPRX ); } /* make sure that the template and the segment are both BCVC */ ASSERT( input->fcTmplt->tmplt.approximant == BCV, status, FINDCHIRPH_EAPRX, FINDCHIRPH_MSGEAPRX ); ASSERT( input->segment->approximant == BCV, status, FINDCHIRPH_EAPRX, FINDCHIRPH_MSGEAPRX ); /* * * point local pointers to input and output pointers * */ /* workspace vectors */ q = params->qVec->data; qBCV = params->qVecBCV->data; qtilde = params->qtildeVec->data; qtildeBCV = params->qtildeVecBCV->data; /* template and data */ inputData = input->segment->data->data->data; inputDataBCV = input->segment->dataBCV->data->data; tmpltSignal = input->fcTmplt->data->data; templateNorm = input->fcTmplt->tmpltNorm; deltaT = params->deltaT; /* some aliases for later use (Thomas) */ deltaTPower2By3 = pow(params->deltaT, 2./3.); deltaTPower1By6 = pow(params->deltaT, 1./6.); /* the length of the chisq bin vec is the number of bin */ /* _boundaries_ so the number of chisq bins is length - 1 */ if ( input->segment->chisqBinVec->length ) { /* * at this point, numChisqBins is only used as a parameter * on the basis of which we decide whether we will do a chisq test or not. * the actual number of chisq bins is: */ numChisqBins = input->segment->chisqBinVec->length - 1; chisqBin = input->segment->chisqBinVec->data; chisqBinBCV = input->segment->chisqBinVecBCV->data; tmpltPower = input->segment->tmpltPowerVec->data; tmpltPowerBCV = input->segment->tmpltPowerVecBCV->data; } /* number of points in a segment */ if (params->qVec->length != params->qVecBCV->length) { ABORT(status, FINDCHIRPBCVH_EQLEN, FINDCHIRPBCVH_MSGEQLEN); } numPoints = params->qVec->length; /* * template parameters, since FindChirpBCVCFilterSegment is run * for every template */ psi0 = input->fcTmplt->tmplt.psi0; psi3 = input->fcTmplt->tmplt.psi3; fFinal = input->fcTmplt->tmplt.fFinal; { /* Calculate deltaEventIndex : the only acceptable clustering */ /* is "window" method, for BCV */ if ( params->clusterMethod == FindChirpClustering_window ) { deltaEventIndex=(UINT4) rint((params->clusterWindow/params->deltaT)+1.0); } else if ( params->clusterMethod == FindChirpClustering_tmplt ) { ABORT( status, FINDCHIRPBCVH_ECLUW, FINDCHIRPBCVH_MSGECLUW ); } /* ignore corrupted data at start and end */ ignoreIndex = ( input->segment->invSpecTrunc / 2 ) + deltaEventIndex; if ( lalDebugLevel & LALINFO ) { CHAR newinfomsg[256]; snprintf( newinfomsg, XLAL_NUM_ELEM(newinfomsg), "chirp time = %e seconds => %d points\n" "invSpecTrunc = %d => ignoreIndex = %d\n", chirpTime, deltaEventIndex, input->segment->invSpecTrunc, ignoreIndex ); LALInfo( status, newinfomsg ); } /* XXX check that we are not filtering corrupted data XXX */ /* XXX this is hardwired to 1/4 segment length XXX */ if ( ignoreIndex > numPoints / 4 ) { ABORT( status, FINDCHIRPH_ECRUP, FINDCHIRPH_MSGECRUP ); } /* XXX reset ignoreIndex to one quarter of a segment XXX */ ignoreIndex = numPoints / 4; } if ( lalDebugLevel & LALINFO ) { CHAR newinfomsg[256]; snprintf( newinfomsg, XLAL_NUM_ELEM(newinfomsg), "filtering from %d to %d\n", ignoreIndex, numPoints - ignoreIndex ); LALInfo( status, newinfomsg ); } /* k that corresponds to fFinal */ deltaF = 1.0 / ( (REAL4) params->deltaT * (REAL4) numPoints ); kFinal = fFinal / deltaF < numPoints/2 ? floor(fFinal / deltaF) : floor(numPoints/2); myfmin = input->segment->fLow; /* assign the values to a1, b1 and b2 */ a1 = input->segment->a1->data[kFinal]; b1 = input->segment->b1->data[kFinal]; b2 = input->segment->b2->data[kFinal]; /* * if one or more of a1, b1 and b2 are 0, output a message */ if ( !fabs(a1) || !fabs(b1) || !fabs(b2) ) { if ( lalDebugLevel & LALINFO ) { CHAR newinfomsg[256]; snprintf( newinfomsg, XLAL_NUM_ELEM(newinfomsg), "a1 = %e b1 = %e b2 = %e\n" "fFinal = %e deltaF = %e numPoints = %d => kFinal = %d\n", a1, b1, b2, fFinal, deltaF, numPoints, kFinal ); LALInfo( status, newinfomsg ); } } /* * * compute qtilde, qtildeBCVC, and q, qBCVC * using the correct combination of inputData and inputDataBCVC * */ memset( qtilde, 0, numPoints * sizeof(COMPLEX8) ); memset( qtildeBCV, 0, numPoints * sizeof(COMPLEX8) ); /* qtilde positive frequency, not DC or nyquist */ for ( k = 1; k < numPoints/2; ++k ) { REAL4 r = a1 * crealf(inputData[k]); REAL4 s = a1 * cimagf(inputData[k]); REAL4 rBCV = b1 * crealf(inputData[k]) + b2 * crealf(inputDataBCV[k]); REAL4 sBCV = b1 * cimagf(inputData[k]) + b2 * cimagf(inputDataBCV[k]); REAL4 x = crealf(tmpltSignal[k]); REAL4 y = 0.0 - cimagf(tmpltSignal[k]); /* note complex conjugate */ qtilde[k] = crectf( r * x - s * y, r * y + s * x ); qtildeBCV[k] = crectf( rBCV * x - sBCV * y, rBCV * y + sBCV * x ); } /* inverse fft to get q, and qBCV */ LALCOMPLEX8VectorFFT( status->statusPtr, params->qVec, params->qtildeVec, params->invPlan ); CHECKSTATUSPTR( status ); LALCOMPLEX8VectorFFT( status->statusPtr, params->qVecBCV, params->qtildeVecBCV, params->invPlan ); CHECKSTATUSPTR( status ); /* * * calculate signal to noise squared * */ /* if full snrsq vector is required, set it to zero */ if ( params->rhosqVec ) memset( params->rhosqVec->data->data, 0, numPoints * sizeof( REAL4 ) ); rhosqThresh = params->rhosqThresh; norm = deltaT / ((REAL4) numPoints) ; /* notice difference from corresponding factor in the sp templates: */ /* no factor of 4 (taken care of in inputData and inputDataBCV */ /* and no segnorm, since we already multiplied by a1, b1 and b2. */ /* normalized snr threhold */ modqsqThresh = rhosqThresh / norm ; /* we threshold on the "modified" chisq threshold computed from */ /* chisqThreshFac = delta^2 * norm / p */ /* rho^2 = norm * modqsq */ /* */ /* So we actually threshold on */ /* */ /* r^2 < chisqThresh * ( 1 + modqsq * chisqThreshFac ) */ /* */ /* which is the same as thresholding on */ /* r^2 < chisqThresh * ( 1 + rho^2 * delta^2 / p ) */ /* and since */ /* chisq = p r^2 */ /* this is equivalent to thresholding on */ /* chisq < chisqThresh * ( p + rho^2 delta^2 ) */ /* */ /* The raw chisq is stored in the database. this quantity is chisq */ /* distributed with 2p-2 degrees of freedom. */ mismatch = 1.0 - input->fcTmplt->tmplt.minMatch; if ( !numChisqBins ) { chisqThreshFac = norm * mismatch * mismatch / (REAL4) numChisqBins; } /* if full snrsq vector is required, store the snrsq */ if ( params->rhosqVec ) { memcpy( params->rhosqVec->name, input->segment->data->name, LALNameLength * sizeof(CHAR) ); memcpy( &(params->rhosqVec->epoch), &(input->segment->data->epoch), sizeof(LIGOTimeGPS) ); params->rhosqVec->deltaT = input->segment->deltaT; for ( j = 0; j < numPoints; ++j ) { REAL4 modqsqSP = crealf(q[j]) * crealf(q[j]) + cimagf(q[j]) * cimagf(q[j]) ; REAL4 modqsqBCV = crealf(qBCV[j]) * crealf(qBCV[j]) + cimagf(qBCV[j]) * cimagf(qBCV[j]) ; REAL4 ImProd = 2.0 * ( - crealf(q[j]) * cimagf(qBCV[j]) + crealf(qBCV[j]) * cimagf(q[j]) ) ; REAL4 newmodqsq = ( 0.5 * sqrt( modqsqSP + modqsqBCV + ImProd ) + 0.5 * sqrt( modqsqSP + modqsqBCV - ImProd ) ) * ( 0.5 * sqrt( modqsqSP + modqsqBCV + ImProd ) + 0.5 * sqrt( modqsqSP + modqsqBCV - ImProd ) ) ; params->rhosqVec->data->data[j] = norm * newmodqsq; } } /* * Here starts the actual constraint code. * */ /* First for debugging purpose. dont erase (Thomas)*/ /* { FILE *V0File, *V1File,*V2File, *alphaFile, *rho1File, *rho2File, *rho3File, *phaseFile, *phaseFileE, *alphaFileE, *rhoFile, *thetavFile; fprintf(stderr, "a1=%e b1=%e b2 =%e fFinal=%e deltTa=%e\n", a1, b1, b2, fFinal, params->deltaT); alphaUnity = pow(fFinal, -2./3.)*pow(params->deltaT,-2./3.); thetab = -(a1 * alphaUnity)/(b2+b1*alphaUnity); thetab = atan(thetab); fprintf(stderr, "alphaMax -->thetab = %e\n", thetab); V0File=fopen("V0File.dat","w"); V1File=fopen("V1File.dat","w"); V2File=fopen("V2File.dat","w"); rho1File=fopen("rho1File.dat","w"); rho2File=fopen("rho2File.dat","w"); rho3File=fopen("rho3File.dat","w"); alphaFile=fopen("alphaFile.dat","w"); thetavFile=fopen("thetavFile.dat","w"); phaseFile=fopen("phaseFile.dat","w"); phaseFileE=fopen("phaseFileE.dat","w"); alphaFileE=fopen("alphaFileE.dat","w"); rhoFile=fopen("rhoFile.dat","w"); for ( j = 0; j < numPoints; ++j ) { REAL4 K1 = q[j].re; REAL4 K2 = qBCV[j].re; REAL4 K3 = q[j].im; REAL4 K4 = qBCV[j].im; REAL4 V0 = q[j].re * q[j].re + qBCV[j].re * qBCV[j].re + q[j].im * q[j].im + qBCV[j].im * qBCV[j].im ; REAL4 V1 = q[j].re * q[j].re + q[j].im * q[j].im - qBCV[j].im * qBCV[j].im - qBCV[j].re * qBCV[j].re; REAL4 V2 = 2 * ( q[j].re * qBCV[j].re + qBCV [j].im * q[j].im); REAL4 rhosqUnconstraint = 0.5 * (V0+sqrt(V1*V1+V2*V2)); REAL4 thetav = atan2(V2,V1); REAL4 Num1 = K2 + K3 ; REAL4 Num2 = K2 - K3 ; REAL4 Den1 = K1 - K4; REAL4 Den2 = K1 + K4; REAL4 InvTan1 = (REAL4) atan2(Num1, Den1); REAL4 InvTan2 = (REAL4) atan2(Num2, Den2); REAL4 omega = 0.5 * InvTan1 + 0.5 * InvTan2 ; fprintf(V0File,"%e\n",V0); fprintf(V1File,"%e\n",V1); fprintf(V2File,"%e\n",V2); fprintf(phaseFileE,"%e\n",0.5 * InvTan1 + 0.5 * InvTan2); fprintf(alphaFileE,"%e\n", (- b2 * tan(omega) / ( a1 + b1 * tan(omega))) *pow(params->deltaT*fFinal, 2.0/3.0) ); fprintf(alphaFile,"%e\n", -(b2 * tan(.5*thetav)) / (a1 + b1* tan(.5*thetav))*pow(params->deltaT*fFinal, 2.0/3.0)); fprintf(phaseFile,"%e\n", thetav); fprintf(rho1File,"%e\n",sqrt(rhosqUnconstraint*norm)); fprintf(rho2File,"%e\n",sqrt(.5*(V0 + V1)*norm)); fprintf(rho3File,"%e\n",sqrt((V0+V1*cos(2*thetab)+V2*sin(2*thetab))/2.*norm)); if (thetab >= 0){ if ( 0 <= thetav && thetav <= 2 * thetab){ rhosqConstraint = sqrt(0.5 * (V0+sqrt(V1*V1+V2*V2))); fprintf(rhoFile,"%e\n",rhosqConstraint); } else if (thetab-LAL_PI <= thetav && thetav < 0) { rhosqConstraint = sqrt((V0 + V1)/2.); fprintf(rhoFile,"%e\n",rhosqConstraint); } else if( (2*thetab < thetav && thetav<LAL_PI ) || thetab-LAL_PI>thetav){ rhosqConstraint =sqrt((V0+V1*cos(2*thetab)+V2*sin(2*thetab))/2.);; fprintf(rhoFile,"%e\n",rhosqConstraint); } else { fprintf(stderr,"must not enter here thetav = %e thetab=%e\n ", thetav , thetab); exit(0); } } else{ if ( 2*thetab <= thetav && thetav <= 0){ rhosqConstraint = 0.5 * (V0+sqrt(V1*V1+V2*V2)); fprintf(rhoFile,"%e\n",sqrt(norm*rhosqConstraint)); } else if (0 < thetav && thetav <= LAL_PI +thetab) { rhosqConstraint = (V0 + V1)/2.; fprintf(rhoFile,"%e\n",sqrt(norm*rhosqConstraint)); } else if( (-LAL_PI-1e-4 <= thetav && thetav < 2*thetab ) || (LAL_PI +thetab <= thetav && thetav <= LAL_PI+1e-4)) { rhosqConstraint =(V0+V1*cos(2*thetab)+V2*sin(2*thetab))/2.; fprintf(rhoFile,"%e\n",sqrt(norm*rhosqConstraint)); } else { fprintf(stderr,"must not enter herethetav = %e thetab=%e %e %e %d\n ",thetav , thetab, V1, V2); fprintf(rhoFile,"%e\n",-1); } } } fclose(rhoFile); fclose(alphaFileE); fclose(thetavFile); fclose(V0File); fclose(V1File); fclose(V2File); fclose(alphaFile); fclose(phaseFile); fclose(phaseFileE); fclose(rho1File); fclose(rho2File); fclose(rho3File); } */ /* let us create some aliases which are going to be constantly used in the * storage of the results. */ mchirp = (1.0 / LAL_MTSUN_SI) * LAL_1_PI * pow( 3.0 / 128.0 / psi0 , ThreeByFive ); m = fabs(psi3) / (16.0 * LAL_MTSUN_SI * LAL_PI * LAL_PI * psi0) ; eta = 3.0 / (128.0*psi0 * pow( (m*LAL_MTSUN_SI*LAL_PI), FiveByThree) ); SQRTNormA1 = sqrt(norm / a1); /* BCV Constraint code (Thomas)*/ /* first we compute what alphaF=1 corresponds to */ alphaUnity = pow(fFinal, -2./3.) * pow(params->deltaT,-2./3.); /* and what is its corresponding angle thetab */ thetab = -(a1 * alphaUnity) / (b2 + b1*alphaUnity); thetab = atan(thetab); if ( lalDebugLevel & LALINFO ) { CHAR newinfomsg[256]; snprintf( newinfomsg, XLAL_NUM_ELEM(newinfomsg), "thetab = %e and alphaUnity = %e\n", thetab, alphaUnity); LALInfo( status, newinfomsg ); } /* look for an event in the filter output */ for ( j = ignoreIndex; j < numPoints - ignoreIndex; ++j ) { /* First, we compute the quantities V0, V1 and V2 */ V0 = crealf(q[j]) * crealf(q[j]) + crealf(qBCV[j]) * crealf(qBCV[j]) + cimagf(q[j]) * cimagf(q[j]) + cimagf(qBCV[j]) * cimagf(qBCV[j]) ; V1 = crealf(q[j]) * crealf(q[j]) + cimagf(q[j]) * cimagf(q[j]) - cimagf(qBCV[j]) * cimagf(qBCV[j]) - crealf(qBCV[j]) * crealf(qBCV[j]); V2 = 2 * ( crealf(q[j]) * crealf(qBCV[j]) + cimagf(qBCV [j]) * cimagf(q[j])); /* and finally the unconstraint SNR which is equivalent to * the unconstrained BCV situation */ rhosqUnconstraint = 0.5*( V0 + sqrt(V1*V1 + V2*V2)); /* We also get the angle between V1 and V2 vectors used later in the * constraint part of BCV filtering. */ thetav = atan2(V2,V1); /* Now, we can compare the angle with thetab. Taking care of the angle is * quite important. */ if (thetab >= 0){ if ( 0 <= thetav && thetav <= 2 * thetab){ rhosqConstraint = rhosqUnconstraint; } else if (thetab-LAL_PI <= thetav && thetav < 0) { rhosqConstraint = (V0 + V1)/2.; } else if( (2*thetab < thetav && thetav<=LAL_PI+1e-4 ) || (-LAL_PI-1e-4<=thetav && thetav < -LAL_PI+thetab)){ rhosqConstraint =(V0+V1*cos(2*thetab)+V2*sin(2*thetab))/2.;; } else { CHAR newinfomsg[256]; snprintf( newinfomsg, XLAL_NUM_ELEM(newinfomsg), "thetab = %e and thetav = %e\n" "thetav not in the range allowed...V1= %e and V2 = %e\n", thetab, thetav, V1, V2 ); LALInfo( status, newinfomsg ); ABORT( status, FINDCHIRPH_EALOC, FINDCHIRPH_MSGEALOC ); } } else{ if ( 2*thetab <= thetav && thetav <= 0){ rhosqConstraint = rhosqUnconstraint; } else if (0 < thetav && thetav <= LAL_PI+thetab ) { rhosqConstraint = (V0 + V1)/2.; } else if( (-LAL_PI-1e-4 <= thetav && thetav < 2*thetab ) || (LAL_PI +thetab <= thetav && thetav <= LAL_PI+1e-4)) { rhosqConstraint =(V0+V1*cos(2*thetab)+V2*sin(2*thetab))/2.; } else { CHAR newinfomsg[256]; snprintf( newinfomsg, XLAL_NUM_ELEM(newinfomsg), "thetab = %e and thetav = %e\n" "thetav not in the range allowed...V1= %e and V2 = %e\n", thetab, thetav, V1, V2 ); LALInfo( status, newinfomsg ); ABORT( status, FINDCHIRPH_EALOC, FINDCHIRPH_MSGEALOC ); } } /* If one want to check that the code is equivalent to BCVFilter.c, just * uncomment the following line. */ /*rhosqConstraint = rhosqUnconstraint; */ if ( rhosqConstraint > modqsqThresh ) { /* alpha computation needed*/ alphaU = -(b2 * tan(.5*thetav)) / (a1 + b1* tan(.5*thetav)); /* I decided to store both constraint and unconstraint alpha */ if (alphaU > alphaUnity) { alphaC = alphaUnity * deltaTPower2By3 ; alphaU*= deltaTPower2By3; } else if (alphaU < 0 ){ alphaC = 0; alphaU*= deltaTPower2By3; } else { alphaU*= deltaTPower2By3; alphaC = alphaU; } if ( ! *eventList ) { /* store the start of the crossing */ eventStartIdx = j; /* if this is the first event, start the list */ thisEvent = *eventList = (SnglInspiralTable *) LALCalloc( 1, sizeof(SnglInspiralTable) ); if ( ! thisEvent ) { ABORT( status, FINDCHIRPH_EALOC, FINDCHIRPH_MSGEALOC ); } /* record the data that we need for the clustering algorithm */ thisEvent->end.gpsSeconds = j; thisEvent->snr = rhosqConstraint; thisEvent->alpha = alphaC; /* use some variable which are not filled in BCV filterinf to keep * track of different intermediate values. */ thisEvent->tau0 = V0; thisEvent->tau2 = V1; thisEvent->tau3 = V2; thisEvent->tau4 = rhosqUnconstraint; thisEvent->tau5 = alphaU; } else if ( !(params->clusterMethod == FindChirpClustering_none) && j <= thisEvent->end.gpsSeconds + deltaEventIndex && rhosqConstraint > thisEvent->snr ) { /* if this is the same event, update the maximum */ thisEvent->end.gpsSeconds = j; thisEvent->snr = rhosqConstraint; thisEvent->alpha = alphaC; thisEvent->tau0 = V0; thisEvent->tau2 = V1; thisEvent->tau3 = V2; thisEvent->tau4 = rhosqUnconstraint; thisEvent->tau5 = alphaU; } else if (j > thisEvent->end.gpsSeconds + deltaEventIndex || params->clusterMethod == FindChirpClustering_none ) { /* clean up this event */ SnglInspiralTable *lastEvent; INT8 timeNS; INT4 timeIndex = thisEvent->end.gpsSeconds; /* set the event LIGO GPS time of the event */ timeNS = 1000000000L * (INT8) (input->segment->data->epoch.gpsSeconds); timeNS += (INT8) (input->segment->data->epoch.gpsNanoSeconds); timeNS += (INT8) (1e9 * timeIndex * deltaT); thisEvent->end.gpsSeconds = (INT4) (timeNS/1000000000L); thisEvent->end.gpsNanoSeconds = (INT4) (timeNS%1000000000L); thisEvent->end_time_gmst = fmod(XLALGreenwichMeanSiderealTime( &(thisEvent->end)), LAL_TWOPI) * 24.0 / LAL_TWOPI; /* hours */ ASSERT( !XLAL_IS_REAL8_FAIL_NAN(thisEvent->end_time_gmst), status, LAL_FAIL_ERR, LAL_FAIL_MSG ); /* set the impuse time for the event */ thisEvent->template_duration = (REAL8) chirpTime; /* record the ifo and channel name for the event */ strncpy( thisEvent->ifo, input->segment->data->name, 2 * sizeof(CHAR) ); strncpy( thisEvent->channel, input->segment->data->name + 3, (LALNameLength - 3) * sizeof(CHAR) ); thisEvent->impulse_time = thisEvent->end; /* copy the template into the event */ thisEvent->psi0 = (REAL4) input->fcTmplt->tmplt.psi0; thisEvent->psi3 = (REAL4) input->fcTmplt->tmplt.psi3; /* chirp mass in units of M_sun */ thisEvent->mchirp = mchirp; thisEvent->eta = eta; thisEvent->f_final = (REAL4) input->fcTmplt->tmplt.fFinal ; /* set the type of the template used in the analysis */ snprintf( thisEvent->search, LIGOMETA_SEARCH_MAX * sizeof(CHAR), "FindChirpBCVC" ); thisEvent->chisq = 0; thisEvent->chisq_dof = 0; thisEvent->sigmasq = SQRTNormA1; thisEvent->eff_distance = input->fcTmplt->tmpltNorm / norm / thisEvent->snr; thisEvent->eff_distance = sqrt( thisEvent->eff_distance ) / deltaTPower1By6; thisEvent->snr *= norm; thisEvent->snr = sqrt( thisEvent->snr ); thisEvent->tau4 = sqrt( thisEvent->tau4 * norm ); /* compute the time since the snr crossing */ thisEvent->event_duration = (REAL8) timeIndex - (REAL8) eventStartIdx; thisEvent->event_duration *= (REAL8) deltaT; /* store the start of the crossing */ eventStartIdx = j; /* allocate memory for the newEvent */ lastEvent = thisEvent; lastEvent->next = thisEvent = (SnglInspiralTable *) LALCalloc( 1, sizeof(SnglInspiralTable) ); if ( ! lastEvent->next ) { ABORT( status, FINDCHIRPH_EALOC, FINDCHIRPH_MSGEALOC ); } /* stick minimal data into the event */ thisEvent->end.gpsSeconds = j; thisEvent->snr = rhosqConstraint; thisEvent->alpha = alphaC; thisEvent->tau0 = V0; thisEvent->tau2 = V1; thisEvent->tau3 = V2; thisEvent->tau4 = rhosqUnconstraint; thisEvent->tau5 = alphaU; } } } /* * * clean up the last event if there is one * */ if ( thisEvent ) { INT8 timeNS; INT4 timeIndex = thisEvent->end.gpsSeconds; /* set the event LIGO GPS time of the event */ timeNS = 1000000000L * (INT8) (input->segment->data->epoch.gpsSeconds); timeNS += (INT8) (input->segment->data->epoch.gpsNanoSeconds); timeNS += (INT8) (1e9 * timeIndex * deltaT); thisEvent->end.gpsSeconds = (INT4) (timeNS/1000000000L); thisEvent->end.gpsNanoSeconds = (INT4) (timeNS%1000000000L); thisEvent->end_time_gmst = fmod(XLALGreenwichMeanSiderealTime( &(thisEvent->end)), LAL_TWOPI) * 24.0 / LAL_TWOPI; /* hours */ ASSERT( !XLAL_IS_REAL8_FAIL_NAN(thisEvent->end_time_gmst), status, LAL_FAIL_ERR, LAL_FAIL_MSG ); /* set the impuse time for the event */ thisEvent->template_duration = (REAL8) chirpTime; /* record the ifo name for the event */ strncpy( thisEvent->ifo, input->segment->data->name, 2 * sizeof(CHAR) ); strncpy( thisEvent->channel, input->segment->data->name + 3, (LALNameLength - 3) * sizeof(CHAR) ); thisEvent->impulse_time = thisEvent->end; /* copy the template into the event */ thisEvent->psi0 = (REAL4) input->fcTmplt->tmplt.psi0; thisEvent->psi3 = (REAL4) input->fcTmplt->tmplt.psi3; /* chirp mass in units of M_sun */ thisEvent->mchirp = mchirp; thisEvent->f_final = (REAL4) input->fcTmplt->tmplt.fFinal; thisEvent->eta = eta; /* set the type of the template used in the analysis */ snprintf( thisEvent->search, LIGOMETA_SEARCH_MAX * sizeof(CHAR), "FindChirpBCVC" ); /* set snrsq, chisq, sigma and effDist for this event */ if ( input->segment->chisqBinVec->length ) { /* we store chisq distributed with 2p - 2 degrees of freedom */ /* in the database. params->chisqVec->data = r^2 = chisq / p */ /* so we multiply r^2 by p here to get chisq */ thisEvent->chisq = params->chisqVec->data[timeIndex] * (REAL4) numChisqBins; thisEvent->chisq_dof = 2 * numChisqBins; /* double for BCV */ } else { thisEvent->chisq = 0; thisEvent->chisq_dof = 0; } thisEvent->sigmasq = SQRTNormA1; thisEvent->eff_distance = input->fcTmplt->tmpltNorm / norm / thisEvent->snr; thisEvent->eff_distance = sqrt( thisEvent->eff_distance ) / deltaTPower1By6; thisEvent->snr *= norm ; thisEvent->snr = sqrt( thisEvent->snr ); thisEvent->tau4 = sqrt( thisEvent->tau4 * norm ); /* compute the time since the snr crossing */ thisEvent->event_duration = (REAL8) timeIndex - (REAL8) eventStartIdx; thisEvent->event_duration *= (REAL8) deltaT; } /* normal exit */ DETATCHSTATUSPTR( status ); RETURN( status ); }
int main(int argc, char *argv[]) { struct options options; INT8 tinj, jitter; gsl_rng *rng; ProcessTable *process_table_head = NULL, *process; ProcessParamsTable *process_params_table_head = NULL; SearchSummaryTable *search_summary_table_head = NULL, *search_summary; TimeSlide *time_slide_table_head = NULL; SimBurst *sim_burst_table_head = NULL; SimBurst **sim_burst = &sim_burst_table_head; /* * Initialize debug handler */ lal_errhandler = LAL_ERR_EXIT; /* * Process table */ process_table_head = process = XLALCreateProcessTableRow(); if(XLALPopulateProcessTable(process, PROGRAM_NAME, lalAppsVCSIdentId, lalAppsVCSIdentStatus, lalAppsVCSIdentDate, 0)) exit(1); XLALGPSTimeNow(&process->start_time); /* * Command line and process params table. */ options = parse_command_line(&argc, &argv, process, &process_params_table_head); if(options.user_tag) snprintf(process->comment, sizeof(process->comment), "%s", options.user_tag); /* * Search summary table */ search_summary_table_head = search_summary = XLALCreateSearchSummaryTableRow(process); if(options.user_tag) snprintf(search_summary->comment, sizeof(search_summary->comment), "%s", options.user_tag); search_summary->nnodes = 1; search_summary->out_start_time = *XLALINT8NSToGPS(&search_summary->in_start_time, options.gps_start_time); search_summary->out_end_time = *XLALINT8NSToGPS(&search_summary->in_end_time, options.gps_end_time); /* * Initialize random number generator */ rng = gsl_rng_alloc(gsl_rng_mt19937); if(options.seed) gsl_rng_set(rng, options.seed); /* * Main loop */ for(tinj = options.gps_start_time; tinj <= options.gps_end_time; tinj += options.time_step * 1e9) { /* * Progress bar. */ XLALPrintInfo("%s: ", argv[0]); XLALPrintProgressBar((tinj - options.gps_start_time) / (double) (options.gps_end_time - options.gps_start_time)); XLALPrintInfo(" complete\n"); /* * Create an injection */ switch(options.population) { case POPULATION_TARGETED: *sim_burst = random_directed_btlwnb(options.ra, options.dec, gsl_ran_flat(rng, 0, LAL_TWOPI), options.minf, options.maxf, options.minbandwidth, options.maxbandwidth, options.minduration, options.maxduration, options.minEoverr2, options.maxEoverr2, rng); break; case POPULATION_ALL_SKY_SINEGAUSSIAN: *sim_burst = random_all_sky_sineGaussian(options.minf, options.maxf, options.q, options.minhrss, options.maxhrss, rng); break; case POPULATION_ALL_SKY_BTLWNB: *sim_burst = random_all_sky_btlwnb(options.minf, options.maxf, options.minbandwidth, options.maxbandwidth, options.minduration, options.maxduration, options.minEoverr2, options.maxEoverr2, rng); break; case POPULATION_STRING_CUSP: *sim_burst = random_string_cusp(options.minf, options.maxf, options.minA, options.maxA, rng); break; default: /* shouldn't get here, command line parsing code * should prevent it */ XLALPrintError("internal error\n"); exit(1); } if(!*sim_burst) { XLALPrintError("can't make injection\n"); exit(1); } /* * Peak time at geocentre in GPS seconds */ /* Add "jitter" to the injection if user requests it */ if(options.jitter > 0) { jitter = gsl_ran_flat(rng, -options.jitter/2, options.jitter/2)*1e9; } else { jitter = 0; } XLALINT8NSToGPS(&(*sim_burst)->time_geocent_gps, tinj + jitter); /* * Peak time at geocentre in GMST radians */ (*sim_burst)->time_geocent_gmst = XLALGreenwichMeanSiderealTime(&(*sim_burst)->time_geocent_gps); /* * Move to next injection */ sim_burst = &(*sim_burst)->next; } XLALPrintInfo("%s: ", argv[0]); XLALPrintProgressBar(1.0); XLALPrintInfo(" complete\n"); /* load time slide document and merge our table rows with its */ if(load_tisl_file_and_merge(options.time_slide_file, &process_table_head, &process_params_table_head, &time_slide_table_head, &search_summary_table_head, &sim_burst_table_head)) exit(1); if(set_instruments(process, time_slide_table_head)) exit(1); snprintf(search_summary->ifos, sizeof(search_summary->ifos), "%s", process->ifos); /* output */ XLALGPSTimeNow(&process->end_time); search_summary->nevents = XLALSimBurstAssignIDs(sim_burst_table_head, process->process_id, time_slide_table_head->time_slide_id, 0); write_xml(options.output, process_table_head, process_params_table_head, search_summary_table_head, time_slide_table_head, sim_burst_table_head); /* done */ gsl_rng_free(rng); XLALDestroyProcessTable(process_table_head); XLALDestroyProcessParamsTable(process_params_table_head); XLALDestroyTimeSlideTable(time_slide_table_head); XLALDestroySearchSummaryTable(search_summary_table_head); XLALDestroySimBurstTable(sim_burst_table_head); exit(0); }
int main( int argc, char **argv ) { INT4 i,j; struct coh_PTF_params *params = NULL; ProcessParamsTable *procpar = NULL; REAL4FFTPlan *fwdplan = NULL; REAL4FFTPlan *psdplan = NULL; REAL4FFTPlan *revplan = NULL; COMPLEX8FFTPlan *invPlan = NULL; REAL4TimeSeries *channel[LAL_NUM_IFO+1]; REAL4FrequencySeries *invspec[LAL_NUM_IFO+1]; RingDataSegments *segments[LAL_NUM_IFO+1]; INT4 numTmplts = 0; INT4 startTemplate = -1; /* index of first template */ INT4 stopTemplate = -1; /* index of last template */ INT4 numSegments = 0; InspiralTemplate *PTFtemplate = NULL; InspiralTemplate *PTFbankhead = NULL; SnglInspiralTable *PTFSpinTmplt = NULL; SnglInspiralTable *PTFSpinTmpltHead = NULL; SnglInspiralTable *PTFNoSpinTmplt = NULL; SnglInspiralTable *PTFNoSpinTmpltHead = NULL; SnglInspiralTable *PTFLastTmplt = NULL; FindChirpTemplate *fcTmplt = NULL; FindChirpTmpltParams *fcTmpltParams = NULL; FindChirpInitParams *fcInitParams = NULL; UINT4 numPoints,ifoNumber,spinTemplate; REAL8Array *PTFM[LAL_NUM_IFO+1]; REAL8Array *PTFN[LAL_NUM_IFO+1]; COMPLEX8VectorSequence *PTFqVec[LAL_NUM_IFO+1]; time_t startTime; LALDetector *detectors[LAL_NUM_IFO+1]; REAL4 *timeOffsets; REAL4 *Fplus; REAL8 FplusTmp; REAL4 *Fcross; REAL8 FcrossTmp; REAL8 detLoc[3]; REAL4TimeSeries UNUSED *pValues[10]; REAL4TimeSeries UNUSED *gammaBeta[2]; LIGOTimeGPS segStartTime; MultiInspiralTable *eventList = NULL; UINT4 numDetectors = 0; UINT4 singleDetector = 0; char bankFileName[256]; startTime = time(NULL); /* set error handlers to abort on error */ set_abrt_on_error(); /* options are parsed and debug level is set here... */ /* no lal mallocs before this! */ params = coh_PTF_get_params( argc, argv ); /* create process params */ procpar = create_process_params( argc, argv, PROGRAM_NAME ); verbose("Read input params %ld \n", time(NULL)-startTime); /* create forward and reverse fft plans */ fwdplan = coh_PTF_get_fft_fwdplan( params ); psdplan = coh_PTF_get_fft_psdplan( params ); revplan = coh_PTF_get_fft_revplan( params ); verbose("Made fft plans %ld \n", time(NULL)-startTime); /* Determine if we are analyzing single or multiple ifo data */ for( ifoNumber = 0; ifoNumber < LAL_NUM_IFO; ifoNumber++) { if ( params->haveTrig[ifoNumber] ) { numDetectors++; } } /* NULL out the pValues pointer array */ for ( i = 0 ; i < 10 ; i++ ) { pValues[i] = NULL; } gammaBeta[0] = NULL; gammaBeta[1] = NULL; if (numDetectors == 0 ) { fprintf(stderr,"You have not specified any detectors to analyse"); return 1; } else if (numDetectors == 1 ) { fprintf(stdout,"You have only specified one detector, why are you using the coherent code? \n"); singleDetector = 1; } /* Convert the file names */ if ( params->bankFile ) strncpy(bankFileName,params->bankFile,sizeof(bankFileName)-1); REAL4 *timeSlideVectors; timeSlideVectors=LALCalloc(1, (LAL_NUM_IFO+1)* params->numOverlapSegments*sizeof(REAL4)); memset(timeSlideVectors, 0, (LAL_NUM_IFO+1) * params->numOverlapSegments * sizeof(REAL4)); for( ifoNumber = 0; ifoNumber < LAL_NUM_IFO; ifoNumber++) { /* Initialize some of the structures */ channel[ifoNumber] = NULL; invspec[ifoNumber] = NULL; segments[ifoNumber] = NULL; PTFM[ifoNumber] = NULL; PTFN[ifoNumber] = NULL; PTFqVec[ifoNumber] = NULL; if ( params->haveTrig[ifoNumber] ) { /* Read in data from the various ifos */ channel[ifoNumber] = coh_PTF_get_data(params,params->channel[ifoNumber],\ params->dataCache[ifoNumber],ifoNumber ); coh_PTF_rescale_data (channel[ifoNumber],1E20); /* compute the spectrum */ invspec[ifoNumber] = coh_PTF_get_invspec( channel[ifoNumber], fwdplan,\ revplan, psdplan, params ); /* create the segments */ segments[ifoNumber] = coh_PTF_get_segments( channel[ifoNumber],\ invspec[ifoNumber], fwdplan, ifoNumber, timeSlideVectors, params ); numSegments = segments[ifoNumber]->numSgmnt; verbose("Created segments for one ifo %ld \n", time(NULL)-startTime); } } /* Determine time delays and response functions */ timeOffsets = LALCalloc(1, numSegments*LAL_NUM_IFO*sizeof( REAL4 )); Fplus = LALCalloc(1, numSegments*LAL_NUM_IFO*sizeof( REAL4 )); Fcross = LALCalloc(1, numSegments*LAL_NUM_IFO*sizeof( REAL4 )); for( ifoNumber = 0; ifoNumber < LAL_NUM_IFO; ifoNumber++) { detectors[ifoNumber] = LALCalloc( 1, sizeof( *detectors[ifoNumber] )); XLALReturnDetector(detectors[ifoNumber] ,ifoNumber); for ( i = 0; i < 3; i++ ) { detLoc[i] = (double) detectors[ifoNumber]->location[i]; } for ( j = 0; j < numSegments; ++j ) { /* Despite being called segStartTime we use the time at the middle * of a segment */ segStartTime = params->startTime; /*XLALGPSAdd(&segStartTime,(j+1)*params->segmentDuration/2.0);*/ XLALGPSAdd(&segStartTime,8.5*params->segmentDuration/2.0); /*XLALGPSMultiply(&segStartTime,0.); XLALGPSAdd(&segStartTime,874610713.072549154);*/ timeOffsets[j*LAL_NUM_IFO+ifoNumber] = (REAL4) XLALTimeDelayFromEarthCenter(detLoc,params->rightAscension, params->declination,&segStartTime); XLALComputeDetAMResponse(&FplusTmp, &FcrossTmp, (const REAL4 (*)[3])detectors[ifoNumber]->response,params->rightAscension, params->declination,0.,XLALGreenwichMeanSiderealTime(&segStartTime)); Fplus[j*LAL_NUM_IFO + ifoNumber] = (REAL4) FplusTmp; Fcross[j*LAL_NUM_IFO + ifoNumber] = (REAL4) FcrossTmp; } LALFree(detectors[ifoNumber]); } numPoints = floor( params->segmentDuration * params->sampleRate + 0.5 ); /* Initialize some of the structures */ ifoNumber = LAL_NUM_IFO; channel[ifoNumber] = NULL; invspec[ifoNumber] = NULL; segments[ifoNumber] = NULL; PTFM[ifoNumber] = NULL; PTFN[ifoNumber] = NULL; PTFqVec[ifoNumber] = NULL; /* Create the relevant structures that will be needed */ fcInitParams = LALCalloc( 1, sizeof( *fcInitParams )); fcTmplt = LALCalloc( 1, sizeof( *fcTmplt ) ); fcTmpltParams = LALCalloc ( 1, sizeof( *fcTmpltParams ) ); fcTmpltParams->approximant = FindChirpPTF; fcTmplt->PTFQtilde = XLALCreateCOMPLEX8VectorSequence( 5, numPoints / 2 + 1 ); /* fcTmplt->PTFBinverse = XLALCreateArrayL( 2, 5, 5 ); fcTmplt->PTFB = XLALCreateArrayL( 2, 5, 5 );*/ fcTmplt->PTFQ = XLALCreateVectorSequence( 5, numPoints ); fcTmpltParams->PTFphi = XLALCreateVector( numPoints ); fcTmpltParams->PTFomega_2_3 = XLALCreateVector( numPoints ); fcTmpltParams->PTFe1 = XLALCreateVectorSequence( 3, numPoints ); fcTmpltParams->PTFe2 = XLALCreateVectorSequence( 3, numPoints ); fcTmpltParams->fwdPlan = XLALCreateForwardREAL4FFTPlan( numPoints, 1 ); fcTmpltParams->deltaT = 1.0/params->sampleRate; for( ifoNumber = 0; ifoNumber < LAL_NUM_IFO; ifoNumber++) { if ( params->haveTrig[ifoNumber] ) { PTFM[ifoNumber] = XLALCreateREAL8ArrayL( 2, 5, 5 ); PTFN[ifoNumber] = XLALCreateREAL8ArrayL( 2, 5, 5 ); PTFqVec[ifoNumber] = XLALCreateCOMPLEX8VectorSequence ( 5, numPoints ); } } /* Create an inverser FFT plan */ invPlan = XLALCreateReverseCOMPLEX8FFTPlan( numPoints, 1 ); /* Read in the tmpltbank xml file */ numTmplts = InspiralTmpltBankFromLIGOLw( &PTFtemplate,bankFileName, startTemplate, stopTemplate ); PTFbankhead = PTFtemplate; /*fake_template (PTFtemplate);*/ for (i = 0; (i < numTmplts); PTFtemplate = PTFtemplate->next, i++) { /* Determine if we can model this template as non-spinning */ spinTemplate = 1; if (PTFtemplate->chi < 0.1) spinTemplate = 0; PTFtemplate->approximant = FindChirpPTF; PTFtemplate->order = LAL_PNORDER_TWO; PTFtemplate->fLower = 38.; /* Generate the Q freq series of the template */ coh_PTF_template(fcTmplt,PTFtemplate,fcTmpltParams); verbose("Generated template %d at %ld \n", i, time(NULL)-startTime); for ( ifoNumber = 0; ifoNumber < LAL_NUM_IFO; ifoNumber++) { if ( params->haveTrig[ifoNumber] ) { memset( PTFM[ifoNumber]->data, 0, 25 * sizeof(REAL8) ); memset( PTFN[ifoNumber]->data, 0, 25 * sizeof(REAL8) ); memset( PTFqVec[ifoNumber]->data, 0, 5 * numPoints * sizeof(COMPLEX8) ); coh_PTF_normalize(params,fcTmplt,invspec[ifoNumber],PTFM[ifoNumber], PTFN[ifoNumber],PTFqVec[ifoNumber], &segments[ifoNumber]->sgmnt[0],invPlan,1); } } spinTemplate = coh_PTF_spin_checker(PTFM,PTFN,params,singleDetector,Fplus,Fcross,numSegments/2); if (spinTemplate) verbose("Template %d treated as spin at %ld \n",i,time(NULL)-startTime); else verbose("Template %d treated as non spin at %ld \n",i,time(NULL)-startTime); if (spinTemplate) { if ( !PTFSpinTmplt ) { PTFSpinTmpltHead = conv_insp_tmpl_to_sngl_table(PTFtemplate,i); PTFSpinTmplt = PTFSpinTmpltHead; } else { PTFLastTmplt = PTFSpinTmplt; PTFSpinTmplt = conv_insp_tmpl_to_sngl_table(PTFtemplate,i); PTFLastTmplt->next = PTFSpinTmplt; } } else { if ( !PTFNoSpinTmplt ) { PTFNoSpinTmpltHead = conv_insp_tmpl_to_sngl_table(PTFtemplate,i); PTFNoSpinTmplt = PTFNoSpinTmpltHead; } else { PTFLastTmplt = PTFNoSpinTmplt; PTFNoSpinTmplt = conv_insp_tmpl_to_sngl_table(PTFtemplate,i); PTFLastTmplt->next = PTFNoSpinTmplt; } } if (! PTFtemplate->event_id) { PTFtemplate->event_id = (EventIDColumn *) LALCalloc(1, sizeof(EventIDColumn) ); PTFtemplate->event_id->id = i; } } coh_PTF_output_tmpltbank(params->spinBankName,PTFSpinTmpltHead,procpar,params); coh_PTF_output_tmpltbank(params->noSpinBankName,PTFNoSpinTmpltHead,procpar,params); verbose("Generated output xml files, cleaning up and exiting at %ld \n", time(NULL)-startTime); LALFree(timeSlideVectors); coh_PTF_cleanup(params,procpar,fwdplan,psdplan,revplan,invPlan,channel, invspec,segments,eventList,NULL,PTFbankhead,fcTmplt,fcTmpltParams, fcInitParams,PTFM,PTFN,PTFqVec,timeOffsets,NULL,Fplus,Fcross,NULL,NULL,\ NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL); while ( PTFSpinTmpltHead ) { PTFSpinTmplt = PTFSpinTmpltHead; PTFSpinTmpltHead = PTFSpinTmplt->next; if ( PTFSpinTmplt->event_id ) { LALFree( PTFSpinTmplt->event_id ); } LALFree( PTFSpinTmplt ); } while ( PTFNoSpinTmpltHead ) { PTFNoSpinTmplt = PTFNoSpinTmpltHead; PTFNoSpinTmpltHead = PTFNoSpinTmplt->next; if ( PTFNoSpinTmplt->event_id ) { LALFree( PTFNoSpinTmplt->event_id ); } LALFree( PTFNoSpinTmplt ); } LALCheckMemoryLeaks(); return 0; }
/** * \deprecated Use XLALComputeDetAMResponse() instead. */ void LALComputeDetAMResponse(LALStatus * status, LALDetAMResponse * pResponse, const LALDetAndSource * pDetAndSrc, const LIGOTimeGPS * gps) { double fplus, fcross; INITSTATUS(status); ATTATCHSTATUSPTR(status); ASSERT(pResponse != (LALDetAMResponse *) NULL, status, DETRESPONSEH_ENULLOUTPUT, DETRESPONSEH_MSGENULLOUTPUT); ASSERT(pDetAndSrc != NULL, status, DETRESPONSEH_ENULLINPUT, DETRESPONSEH_MSGENULLINPUT); ASSERT(gps != (LIGOTimeGPS *) NULL, status, DETRESPONSEH_ENULLINPUT, DETRESPONSEH_MSGENULLINPUT); /* source coordinates must be in equatorial system */ ASSERT(pDetAndSrc->pSource->equatorialCoords.system == COORDINATESYSTEM_EQUATORIAL, status, DETRESPONSEH_ESRCNOTEQUATORIAL, DETRESPONSEH_MSGESRCNOTEQUATORIAL); XLALComputeDetAMResponse(&fplus, &fcross, pDetAndSrc->pDetector->response, pDetAndSrc->pSource->equatorialCoords.longitude, pDetAndSrc->pSource->equatorialCoords.latitude, pDetAndSrc->pSource->orientation, XLALGreenwichMeanSiderealTime(gps)); pResponse->plus = fplus; pResponse->cross = fcross; pResponse->scalar = 0.0; /* not implemented */ DETATCHSTATUSPTR(status); RETURN(status); }