int XLALSnglSimInspiralTest ( SimInspiralTable **simHead, SnglInspiralTable **eventHead, SimInspiralTable **missedSimHead, SnglInspiralTable **missedSnglHead, INT8 injectWindowNS ) { /* Note: we are assuming that both the inspiral and */ /* injection events are time sorted */ SimInspiralTable *thisSimEvent = *simHead; SimInspiralTable *thisMissedSim= NULL; SimInspiralTable *prevSimEvent = NULL; SnglInspiralTable *thisEvent = *eventHead; SnglInspiralTable *prevEvent = NULL; SnglInspiralTable *thisMissed = NULL; EventIDColumn *thisId = NULL; int numSimFound = 0; int coincidence = 0; INT8 simGeocentTime, simSiteTime, inspiralTime; INT8 earthRadiusNS = (INT8) ( 1e9 * 2 * LAL_REARTH_SI / LAL_C_SI ); *simHead = NULL; *eventHead = NULL; if ( ! thisEvent ) { XLALPrintInfo( "No triggers in input data, all injections missed\n" ); *missedSimHead = thisSimEvent; return(0); } else { /* begin loop over the sim_inspiral events */ while ( thisSimEvent ) { coincidence = 0; /* find the end time of the SimEvent */ simGeocentTime = geocent_end_time( thisSimEvent ); /* find the first inspiral event after the current sim event */ while ( thisEvent ) { /* compute the time in nanosec for thisEvent */ inspiralTime = XLALGPSToINT8NS( &(thisEvent->end) ); if( inspiralTime < (simGeocentTime - earthRadiusNS - injectWindowNS ) ) { /* discard this event and move on to the next one */ if ( ! *missedSnglHead ) { *missedSnglHead = thisMissed = thisEvent; } else { thisMissed = thisMissed->next = thisEvent; } if ( prevEvent ) prevEvent->next = thisEvent->next; thisEvent = thisEvent->next; thisMissed->next = NULL; XLALPrintInfo( "-" ); } else { /* we have reached the negative coincincidence window */ break; } } while ( thisEvent ) { /* compute the time in nanosec for thisEvent */ inspiralTime = XLALGPSToINT8NS( &(thisEvent->end) ); if( inspiralTime < (simGeocentTime + earthRadiusNS + injectWindowNS ) ) { /* this event may be in coincidence window, need to check site * end time */ simSiteTime = XLALReturnSimInspiralEndTime( thisSimEvent, thisEvent->ifo ); if ( (inspiralTime > (simSiteTime - injectWindowNS)) && (inspiralTime < (simSiteTime + injectWindowNS)) ) { /* this event is within the coincidence window */ /* store the sim inspiral in the event_id's for this sngl */ thisId = thisEvent->event_id; while ( thisId ) { thisId->simInspiralTable = thisSimEvent; thisId = thisId->next; } /* store this event and move on to the next one */ if ( ! *eventHead ) *eventHead = thisEvent; prevEvent = thisEvent; thisEvent = thisEvent->next; coincidence = 1; XLALPrintInfo( "+" ); } else { /* discard this event and move on to the next one */ if ( ! *missedSnglHead ) { *missedSnglHead = thisMissed = thisEvent; } else { thisMissed = thisMissed->next = thisEvent; } if ( prevEvent ) prevEvent->next = thisEvent->next; thisEvent = thisEvent->next; thisMissed->next = NULL; XLALPrintInfo( "-" ); } } else { /* we have reached the end of the positive coincincidence window */ break; } } if ( coincidence ) { /* keep this sim event in the list and move to the next sim event */ if ( ! *simHead ) *simHead = thisSimEvent; prevSimEvent = thisSimEvent; ++numSimFound; thisSimEvent = thisSimEvent->next; XLALPrintInfo( "F" ); } else { /* save this sim event in the list of missed events... */ if ( ! *missedSimHead ) { *missedSimHead = thisMissedSim = thisSimEvent; } else { thisMissedSim = thisMissedSim->next = thisSimEvent; } /* ...and remove it from the list of found events */ if ( prevSimEvent ) prevSimEvent->next = thisSimEvent->next; XLALPrintInfo( "M" ); /* move to the next sim in the list */ thisSimEvent = thisSimEvent->next; /* make sure the missed sim list is terminated */ thisMissedSim->next = NULL; } if ( ! thisEvent ) { /* these are no more events to process so all the rest of the */ /* injections must be put in the missed injections list */ if ( ! *missedSimHead ) { /* this and any subsequent events are in the missed sim list */ if ( thisSimEvent ) thisMissedSim = *missedSimHead = thisSimEvent; } else { if ( thisSimEvent ) { /* append the rest of the list to the list of missed injections */ thisMissedSim = thisMissedSim->next = thisSimEvent; } else { /* there are no injections after this one */ thisMissedSim = thisMissedSim->next = NULL; } } /* terminate the list of found injections correctly */ if ( prevSimEvent ) prevSimEvent->next = NULL; while ( thisMissedSim ) { /* count the number of injections just stuck in the missed list */ XLALPrintInfo( "M" ); thisMissedSim = thisMissedSim->next; } thisSimEvent = NULL; break; } } if ( thisEvent ) { while( thisEvent ) { /* discard this event and move on to the next one */ if ( ! *missedSnglHead ) { *missedSnglHead = thisMissed = thisEvent; } else { thisMissed = thisMissed->next = thisEvent; } if ( prevEvent ) prevEvent->next = thisEvent->next; thisEvent = thisEvent->next; thisMissed->next = NULL; XLALPrintInfo( "-" ); } } } XLALPrintInfo( "\n" ); return( numSimFound ); }
REAL8 XLALEThincaParameterForInjection( SimInspiralTable *injection, SnglInspiralTable *trigger ) { /* Trigger parameters */ REAL8 fLower; REAL8 mTotal; REAL8 tau0; REAL8 eta; /* Inj parameters */ InspiralTemplate injTmplt; /* Used to calculate parameters */ INT8 injEndTime; /* Parameter differences */ REAL8 dtC, dt0, dt3; REAL8 eMatch; LALStatus status; #ifndef LAL_NDEBUG if ( !injection || !trigger ) XLAL_ERROR_REAL8( XLAL_EFAULT ); #endif memset( &status, 0, sizeof(LALStatus)); /* We need the tau0 and tau3 for the injection */ /* To do this, we will need to calculate the lower frequency used in the * case of the inspiral trigger */ mTotal = trigger->mass1 + trigger->mass2; eta = trigger->eta; tau0 = trigger->tau0; mTotal = mTotal * LAL_MTSUN_SI; fLower = 5.0 / (256.0 * eta * pow(mTotal, 5.0/3.0) * tau0 ); fLower = pow(fLower, 3.0/8.0) / LAL_PI; XLALPrintInfo("%s: fLower found to be %e\n", __func__, fLower ); /* Now populate the inspiral template with relevant parameters */ injTmplt.mass1 = injection->mass1; injTmplt.mass2 = injection->mass2; injTmplt.massChoice = m1Andm2; injTmplt.fLower = fLower; injTmplt.order = LAL_PNORDER_THREE_POINT_FIVE; LALInspiralParameterCalc( &status, &injTmplt ); /* Get the GPS time from the injection*/ injEndTime = XLALReturnSimInspiralEndTime( injection, trigger->ifo ); dtC = ( injEndTime - XLALGPSToINT8NS( &(trigger->end_time) ) ) * 1.0e-9; dt0 = injTmplt.t0 - trigger->tau0; dt3 = injTmplt.t3 - trigger->tau3; eMatch = trigger->Gamma[0] * dtC * dtC + 2.0 * trigger->Gamma[1] * dtC * dt0 + 2.0 * trigger->Gamma[2] * dtC * dt3 + trigger->Gamma[3] * dt0 * dt0 + 2.0 * trigger->Gamma[4] * dt0 * dt3 + trigger->Gamma[5] * dt3 * dt3; return eMatch; }