Esempio n. 1
0
double NullMatch::findBestDrawOrder(Definition *pcDef) {
	// Compute the global error
	double dBestMatch = computeMatch(pcDef);

	/*
	 * Remember it as the best draw order
	 * NOTE: Have to do this after computeMatch() since
	 * it also saves the errors
	 */
	symbol()->saveBestDrawOrder(dBestMatch);

	// Do not do any segment swapping
	return (dBestMatch);
}
Esempio n. 2
0
FakedFont FontFamily::getClosestMatch(FontStyle style) const {
  const Font* bestFont = nullptr;
  int bestMatch = 0;
  for (size_t i = 0; i < mFonts.size(); i++) {
    const Font& font = mFonts[i];
    int match = computeMatch(font.style, style);
    if (i == 0 || match < bestMatch) {
      bestFont = &font;
      bestMatch = match;
    }
  }
  if (bestFont != nullptr) {
    return FakedFont{bestFont->typeface.get(),
                     computeFakery(style, bestFont->style)};
  }
  return FakedFont{nullptr, FontFakery()};
}
INT4 main (INT4 argc, char* argv[])
{
    UINT4 startAtZero = 1;
    // RNG seed
    UINT8 seed;

    REAL8 desiredDeltaF;

    // if passed parameters, assume first parameter is the seed
    if(argc > 1)
    {
        seed = atoi(argv[1]);
        if(seed == 0)
        {
            seed = time(0);
        }

        if(argc > 2)
        {
            desiredDeltaF = atof(argv[2]);
        }
        else
        {
            desiredDeltaF = 0.1;
        }
    }
    else
    {
        seed = time(0);
    }

    // seed the RNG
    srand(seed);
    printf("Starting TestTaylorTFourier with seed %" LAL_UINT8_FORMAT "\n" , seed);

    // define different orders
    LALSimInspiralSpinOrder spinO = 7;
    LALSimInspiralTidalOrder tideO = 0;
    INT4 phaseO = 7;
    INT4 amplitudeO = 3;

    // define parameters
    REAL8 phiRef, v0, m1, m2, r, s1x, s1y, s1z, s2x, s2y, s2z, lnhatx, lnhaty, lnhatz, e1x, e1y, e1z, lambda1, lambda2, quadparam1, quadparam2;

    v0 = 1.;

    // deformability parameters turned off
    lambda1 = 0.;
    lambda2 = 0.;
    quadparam1 = 0.;
    quadparam2 = 0.;

    // define instrument projection parameters
    REAL8 Fplus, Fcross;

    // define range for the parameters
    REAL8 m1Min, m1Max, m2Min, m2Max, chi1Min, chi1Max, chi2Min, chi2Max, rMin, rMax;

    m1Min = 1.; // in solar masses
    m1Max = 2.5; // in solar masses
    m2Min = 1.; // in solar masses
    m2Max = 2.5; // in solar masses
    chi1Min = 0.;
    chi1Max = 1.;
    chi2Min = 0.;
    chi2Max = 1.;
    rMin = 3.e24;
    rMax = 3.e24;

    // randomize parameters
    randomize(&phiRef, &m1, &m2, &r, &s1x, &s1y, &s1z, &s2x, &s2y, &s2z, &lnhatx, &lnhaty, &lnhatz, &e1x, &e1y, &e1z, &Fplus, &Fcross, m1Min, m1Max, m2Min, m2Max,  chi1Min, chi1Max, chi2Min, chi2Max, rMin, rMax);

    // misc parameters
    REAL8 tTot;
    REAL8 deltaF;
    INT4 nSamples;
    REAL8 fMin;
    REAL8 fMax;
    REAL8 tInit;
    REAL8 desiredFMin;
    UINT4 i;

    fMax = 2000.;
    desiredFMin = 10.;

    REAL8 M = m1 + m2;
    REAL8 eta = (m1*m2)/(M*M);
    // define time series for time domain waveform
    REAL8TimeSeries* hPlus = 0;
    REAL8TimeSeries* hCross = 0;

    // define extra parameters for TD WF
    REAL8 deltaT;

    REAL8 fStart = 9.;
    REAL8 fRef = 70.;
    INT4 phiRefAtEnd = 0;

    // more misc variables
    COMPLEX16* hPlusTildeTD;
    COMPLEX16* hCrossTildeTD;

    REAL8 factTukey, t1, t2, t3, t4;
    REAL8 sinfact, t;

    fftw_complex* ftilde_data;
    fftw_plan plan;

    INT4 iStart, jStart, nSkip;
    REAL8 rStop;

    INT4 nMax;


    // define frequency series for FD WFs
    COMPLEX16FrequencySeries* hPlusTildeFD = 0;
    COMPLEX16FrequencySeries* hCrossTildeFD = 0;

    INT4 kMax;
    REAL8 normalizationTD;
    REAL8 meanDeltaT;
    REAL8 match;


    printf("TaylorT4:\nStarting time domain...\n");

    // compute TD WF with deltaT=1 to get signal time duration
    deltaT = 1.;
    XLALSimInspiralSpinTaylorT4(&hPlus, &hCross, phiRef, v0, deltaT, m1, m2, fStart, fRef, r, s1x, s1y, s1z, s2x, s2y, s2z, lnhatx, lnhaty, lnhatz, e1x, e1y, e1z, lambda1, lambda2, quadparam1, quadparam2, spinO, tideO, phaseO, amplitudeO);

    // compute deltaT necessary for Nyquist frequency at fMax
    tTot = -(hPlus->epoch.gpsSeconds + 1.e-9*hPlus->epoch.gpsNanoSeconds);
    deltaF = 1./tTot;
    nSamples = 2.*fMax/deltaF;
    deltaT = tTot/nSamples;

    // compute TD WF with good deltaT
    XLALDestroyREAL8TimeSeries(hPlus);
    XLALDestroyREAL8TimeSeries(hCross);
    XLALSimInspiralSpinTaylorT4(&hPlus, &hCross, phiRef, v0, deltaT, m1, m2, fStart, fRef, r, s1x, s1y, s1z, s2x, s2y, s2z, lnhatx, lnhaty, lnhatz, e1x, e1y, e1z, lambda1, lambda2, quadparam1, quadparam2, spinO, tideO, phaseO, amplitudeO);

    // define and allocate DFT of TD WF
    hPlusTildeTD = (COMPLEX16*)malloc(sizeof(COMPLEX16)*(hPlus->data->length));
    hCrossTildeTD = (COMPLEX16*)malloc(sizeof(COMPLEX16)*(hCross->data->length));

    tInit = hPlus->epoch.gpsSeconds + 1.e-9*hPlus->epoch.gpsNanoSeconds;
    deltaF = 1./(deltaT*(hPlus->data->length));

    // define Tukey window parameters
    factTukey = (-5.*LAL_G_SI*M)/(((256.*eta*LAL_C_SI)*LAL_C_SI)*LAL_C_SI);
    t1 = tInit;
    t2 = factTukey*pow((LAL_PI*LAL_G_SI)*M*9.5/(((((REAL8)LAL_C_SI)*LAL_C_SI)*LAL_C_SI)), -8./3.); // 9.5 Hertz Newtonian
    t3 = factTukey*50625.; // 15M separation Newtonian
    t4 = 0.;

    // apply Tukey window
    i = 0;
    t = tInit;
    while(t < t2)
    {
        sinfact = sin(LAL_PI_2*(t - t1)/(t2 - t1));
        hPlus->data->data[i] *= sinfact*sinfact;
        hCross->data->data[i] *= sinfact*sinfact;
        i++;
        t = tInit + i*deltaT;
    }

    i = hPlus->data->length-1;
    t = tInit + i*deltaT;
    while(t > t3)
    {
        sinfact = sin(LAL_PI_2*(t - t4)/(t3 - t4));
        hPlus->data->data[i] *= sinfact*sinfact;
        hCross->data->data[i] *= sinfact*sinfact;
        i--;
        t = tInit + i*deltaT;
    }

    // compute the DFTs, applying the necessary time shift
    ftilde_data = (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*(hPlus->data->length));
    plan = fftw_plan_dft_r2c_1d(hPlus->data->length, hPlus->data->data, ftilde_data, FFTW_ESTIMATE);
    fftw_execute(plan);
    fftw_destroy_plan(plan);

    for(i = 0; i <= hPlus->data->length >> 1; i++)
    {
        hPlusTildeTD[i] = deltaT*cexp(-I*LAL_TWOPI*i*deltaF*tInit)*ftilde_data[i];
    }

    plan = fftw_plan_dft_r2c_1d(hCross->data->length, hCross->data->data, ftilde_data, FFTW_ESTIMATE);
    fftw_execute(plan);
    fftw_destroy_plan(plan);

    for(i = 0; i <= hCross->data->length >> 1; i++)
    {
        hCrossTildeTD[i] = deltaT*cexp(-I*LAL_TWOPI*i*deltaF*tInit)*ftilde_data[i];
    }

    fftw_free(ftilde_data);


    // compute fMin and deltaF for the frequency domain WFs, close to desiredFMin and desiredDeltaF but a multiple of deltaF for the TD WF
    iStart = (INT4)ceil(desiredFMin/deltaF);
    nSkip = (INT4)ceil(desiredDeltaF/deltaF);
    iStart -= iStart % nSkip;
    fMin = iStart*deltaF;
    deltaF *= nSkip;
    if(startAtZero)
    {
        jStart = iStart/nSkip;
    }
    else
    {
        jStart = 0;
    }

    // set maximum frequency for the comparison
    rStop = 20.; // frequency of r = 20M
    fMax = LAL_C_SI*(LAL_C_SI*(LAL_C_SI/(LAL_PI*LAL_G_SI*M*rStop*sqrt(rStop))));

    nMax = (INT4)floor((fMax - fMin)/deltaF) + jStart;


    // normalize TD WF
    normalizationTD = normalizeTD(hPlusTildeTD, hCrossTildeTD, Fplus, Fcross, iStart, jStart, nSkip, nMax);

    printf("Matches:\n");

    for(kMax = 0; kMax <= 10; kMax++) // loop over kMax
    {
        //compute FD WF
        XLALSimInspiralSpinTaylorT4Fourier(&hPlusTildeFD, &hCrossTildeFD, fMin, fMax, deltaF, kMax, phiRef, v0, m1, m2, fStart, fRef, r, s1x, s1y, s1z, s2x, s2y, s2z, lnhatx, lnhaty, lnhatz, e1x, e1y, e1z, lambda1, lambda2, quadparam1, quadparam2, spinO, tideO, phaseO, amplitudeO, phiRefAtEnd);

        // XLALSimInspiralSpinTaylorT4 and XLALSimInspiralSpinTaylorT4Fourier return with a slight time offset between the two. We get rid of that.
        if(startAtZero)
        {
            meanDeltaT = meanTimeOffset(hPlusTildeFD, hCrossTildeFD, hPlusTildeTD, hCrossTildeTD, Fplus, Fcross, iStart, jStart, nSkip, nMax, 0., deltaF);
            for(i = 0; i < hPlusTildeFD->data->length; i++)
            {
                hPlusTildeFD->data->data[i] *= cexp(I*LAL_TWOPI*(i*deltaF)*meanDeltaT);
                hCrossTildeFD->data->data[i] *= cexp(I*LAL_TWOPI*(i*deltaF)*meanDeltaT);
            }
        }
        else
        {
            meanDeltaT = meanTimeOffset(hPlusTildeFD, hCrossTildeFD, hPlusTildeTD, hCrossTildeTD, Fplus, Fcross, iStart, jStart, nSkip, nMax, fMin, deltaF);
            for(i = 0; i < hPlusTildeFD->data->length; i++)
            {
                hPlusTildeFD->data->data[i] *= cexp(I*LAL_TWOPI*(fMin + i*deltaF)*meanDeltaT);
                hCrossTildeFD->data->data[i] *= cexp(I*LAL_TWOPI*(fMin + i*deltaF)*meanDeltaT);
            }
        }

        // compute match
        match = normalizationTD*computeMatch(hPlusTildeFD, hCrossTildeFD, hPlusTildeTD, hCrossTildeTD, Fplus, Fcross, iStart, jStart, nSkip, nMax);
        printf("kMax = %2d: %.15f\n", kMax, match);

        XLALDestroyCOMPLEX16FrequencySeries(hPlusTildeFD);
        XLALDestroyCOMPLEX16FrequencySeries(hCrossTildeFD);
    }

    XLALDestroyREAL8TimeSeries(hPlus);
    XLALDestroyREAL8TimeSeries(hCross);
    free(hPlusTildeTD);
    free(hCrossTildeTD);








    printf("\nTaylorT2:\nStarting time domain...\n");

    // compute TD WF with deltaT=1 to get signal time duration
    deltaT = 1.;
    XLALSimInspiralSpinTaylorT2(&hPlus, &hCross, phiRef, v0, deltaT, m1, m2, fStart, fRef, r, s1x, s1y, s1z, s2x, s2y, s2z, lnhatx, lnhaty, lnhatz, e1x, e1y, e1z, lambda1, lambda2, quadparam1, quadparam2, spinO, tideO, phaseO, amplitudeO);

    // compute deltaT necessary for Nyquist frequency at fMax
    tTot = -(hPlus->epoch.gpsSeconds + 1.e-9*hPlus->epoch.gpsNanoSeconds);
    deltaF = 1./tTot;
    nSamples = 2.*fMax/deltaF;
    deltaT = tTot/nSamples;

    // compute TD WF with good deltaT
    XLALDestroyREAL8TimeSeries(hPlus);
    XLALDestroyREAL8TimeSeries(hCross);
    XLALSimInspiralSpinTaylorT2(&hPlus, &hCross, phiRef, v0, deltaT, m1, m2, fStart, fRef, r, s1x, s1y, s1z, s2x, s2y, s2z, lnhatx, lnhaty, lnhatz, e1x, e1y, e1z, lambda1, lambda2, quadparam1, quadparam2, spinO, tideO, phaseO, amplitudeO);

    // define and allocate DFT of TD WF
    hPlusTildeTD = (COMPLEX16*)malloc(sizeof(COMPLEX16)*(hPlus->data->length));
    hCrossTildeTD = (COMPLEX16*)malloc(sizeof(COMPLEX16)*(hCross->data->length));

    tInit = hPlus->epoch.gpsSeconds + 1.e-9*hPlus->epoch.gpsNanoSeconds;
    deltaF = 1./(deltaT*(hPlus->data->length));

    // define Tukey window parameters
    factTukey = (-5.*LAL_G_SI*M)/(((256.*eta*LAL_C_SI)*LAL_C_SI)*LAL_C_SI);
    t1 = tInit;
    t2 = factTukey*pow((LAL_PI*LAL_G_SI)*M*9.5/(((((REAL8)LAL_C_SI)*LAL_C_SI)*LAL_C_SI)), -8./3.); // 9.5 Hertz Newtonian
    t3 = factTukey*25.*25.*25.*25.; // 25M separation Newtonian. For TaylorT2 we need a huge half-Hann window at the end for some reason.
    t4 = 0.;

    // apply Tukey window
    i = 0;
    t = tInit;
    while(t < t2)
    {
        sinfact = sin(LAL_PI_2*(t - t1)/(t2 - t1));
        hPlus->data->data[i] *= sinfact*sinfact;
        hCross->data->data[i] *= sinfact*sinfact;
        i++;
        t = tInit + i*deltaT;
    }

    i = hPlus->data->length-1;
    t = tInit + i*deltaT;
    while(t > t3)
    {
        sinfact = sin(LAL_PI_2*(t - t4)/(t3 - t4));
        hPlus->data->data[i] *= sinfact*sinfact;
        hCross->data->data[i] *= sinfact*sinfact;
        i--;
        t = tInit + i*deltaT;
    }

    // compute the DFTs, applying the necessary time shift
    ftilde_data = (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*(hPlus->data->length));
    plan = fftw_plan_dft_r2c_1d(hPlus->data->length, hPlus->data->data, ftilde_data, FFTW_ESTIMATE);
    fftw_execute(plan);
    fftw_destroy_plan(plan);

    for(i = 0; i <= hPlus->data->length >> 1; i++)
    {
        hPlusTildeTD[i] = deltaT*cexp(-I*LAL_TWOPI*i*deltaF*tInit)*ftilde_data[i];
    }

    plan = fftw_plan_dft_r2c_1d(hCross->data->length, hCross->data->data, ftilde_data, FFTW_ESTIMATE);
    fftw_execute(plan);
    fftw_destroy_plan(plan);

    for(i = 0; i <= hCross->data->length >> 1; i++)
    {
        hCrossTildeTD[i] = deltaT*cexp(-I*LAL_TWOPI*i*deltaF*tInit)*ftilde_data[i];
    }

    fftw_free(ftilde_data);


    // compute fMin and deltaF for the frequency domain WFs, close to desiredFMin and desiredDeltaF but a multiple of deltaF for the TD WF
    iStart = (INT4)ceil(desiredFMin/deltaF);
    nSkip = (INT4)ceil(desiredDeltaF/deltaF);
    iStart -= iStart % nSkip;
    fMin = iStart*deltaF;
    deltaF *= nSkip;
    if(startAtZero)
    {
        jStart = iStart/nSkip;
    }
    else
    {
        jStart = 0;
    }

    // set maximum frequency for the comparison
    rStop = 25.; // frequency of r = 20M
    fMax = LAL_C_SI*(LAL_C_SI*(LAL_C_SI/(LAL_PI*LAL_G_SI*M*rStop*sqrt(rStop))));

    nMax = (INT4)floor((fMax - fMin)/deltaF) + jStart;


    // define frequency series for FD WFs
    hPlusTildeFD = 0;
    hCrossTildeFD = 0;

    // normalize TD WF
    normalizationTD = normalizeTD(hPlusTildeTD, hCrossTildeTD, Fplus, Fcross, iStart, jStart, nSkip, nMax);

    printf("Matches:\n");

    for(kMax = 0; kMax <= 10; kMax++) // loop over kMax
    {
        //compute FD WF
        XLALSimInspiralSpinTaylorT2Fourier(&hPlusTildeFD, &hCrossTildeFD, fMin, fMax, deltaF, kMax, phiRef, v0, m1, m2, fStart, fRef, r, s1x, s1y, s1z, s2x, s2y, s2z, lnhatx, lnhaty, lnhatz, e1x, e1y, e1z, lambda1, lambda2, quadparam1, quadparam2, spinO, tideO, phaseO, amplitudeO, phiRefAtEnd);

        // XLALSimInspiralSpinTaylorT2 and XLALSimInspiralSpinTaylorT2Fourier return with a slight time offset between the two. We get rid of that.
        if(startAtZero)
        {
            meanDeltaT = meanTimeOffset(hPlusTildeFD, hCrossTildeFD, hPlusTildeTD, hCrossTildeTD, Fplus, Fcross, iStart, jStart, nSkip, nMax, 0., deltaF);
            for(i = 0; i < hPlusTildeFD->data->length; i++)
            {
                hPlusTildeFD->data->data[i] *= cexp(I*LAL_TWOPI*(i*deltaF)*meanDeltaT);
                hCrossTildeFD->data->data[i] *= cexp(I*LAL_TWOPI*(i*deltaF)*meanDeltaT);
            }
        }
        else
        {
            meanDeltaT = meanTimeOffset(hPlusTildeFD, hCrossTildeFD, hPlusTildeTD, hCrossTildeTD, Fplus, Fcross, iStart, jStart, nSkip, nMax, fMin, deltaF);
            for(i = 0; i < hPlusTildeFD->data->length; i++)
            {
                hPlusTildeFD->data->data[i] *= cexp(I*LAL_TWOPI*(fMin + i*deltaF)*meanDeltaT);
                hCrossTildeFD->data->data[i] *= cexp(I*LAL_TWOPI*(fMin + i*deltaF)*meanDeltaT);
            }
        }

        // compute match
        match = normalizationTD*computeMatch(hPlusTildeFD, hCrossTildeFD, hPlusTildeTD, hCrossTildeTD, Fplus, Fcross, iStart, jStart, nSkip, nMax);
        printf("kMax = %2d: %.15f\n", kMax, match);

        XLALDestroyCOMPLEX16FrequencySeries(hPlusTildeFD);
        XLALDestroyCOMPLEX16FrequencySeries(hCrossTildeFD);
    }

    XLALDestroyREAL8TimeSeries(hPlus);
    XLALDestroyREAL8TimeSeries(hCross);
    free(hPlusTildeTD);
    free(hCrossTildeTD);

    fftw_cleanup();


    return XLAL_SUCCESS;
}