Ejemplo n.º 1
0
        public static double[] FitLorenzianToSlaveData(CavityScanData data, double limitLow, double limitHigh)
        {
            double[] voltages = data.parameters.CalculateRampVoltages();

            LorentzianFitter lorentzianFitter = new LorentzianFitter();

            // takes the parameters (in this order, in the double[])
            // N: background
            // Q: signal
            // c: centre
            // w: width

            dataPoint max = getMax(data.SlavePhotodiodeData);
            dataPoint min = getMin(data.SlavePhotodiodeData);

            lorentzianFitter.Fit(voltages, data.SlavePhotodiodeData,
                                 new double[] { min.value, max.value - min.value,
                                                voltages[max.index], (data.parameters.High - data.parameters.Low) / 10, });

            double[] coefficients = lorentzianFitter.Parameters;

            fitFailSafe(coefficients, limitLow, limitHigh);

            return(new double[] { coefficients[3], coefficients[2], coefficients[1], coefficients[0] }); //to be consistent with old convention.
        }
Ejemplo n.º 2
0
        public static double[] FitLorenzianToData(double[] voltages, double[] signal)
        {
            double high = getMax(voltages).value;
            double low  = getMin(voltages).value;

            System.Diagnostics.Debug.WriteLine("   " + low.ToString() + "   " + high.ToString());
            LorentzianFitter lorentzianFitter = new LorentzianFitter();

            // takes the parameters (in this order, in the double[])
            // N: background
            // Q: signal
            // c: centre
            // w: width

            dataPoint max = getMax(signal);
            dataPoint min = getMin(signal);

            lorentzianFitter.Fit(voltages, signal,
                                 new double[] { min.value, max.value - min.value,
                                                voltages[max.index], (high - low) / 10, });

            double[] coefficients = lorentzianFitter.Parameters;

            fitFailSafe(coefficients, low, high);

            return(new double[] { coefficients[3], coefficients[2], coefficients[1], coefficients[0] }); //to be consistent with old convention.
        }
Ejemplo n.º 3
0
        public static LorentzianFit FitLorentzianToData(double[] voltages, double[] signal, LorentzianFit bestGuess)
        {
            LorentzianFitter lorentzianFitter = new LorentzianFitter();

            lorentzianFitter.Fit(voltages, signal, new double[] { bestGuess.Background, bestGuess.Amplitude, bestGuess.Centre, bestGuess.Width });
            double[] coefficients = lorentzianFitter.Parameters;

            LorentzianFit fit = new LorentzianFit(coefficients[0], coefficients[1], coefficients[2], coefficients[3]);

            double minCentrePosition = voltages.Min();
            double maxCentrePosition = voltages.Max();

            fit = fitFailSafe(fit, minCentrePosition, maxCentrePosition);

            return(fit);
        }
Ejemplo n.º 4
0
        //This function speeds up the fitting process by passing the last fitted parameters as a guess,
        // and by restricting the fit to only those points near to the peak
        public static double[] FitLorenzianToData(double[] voltages, double[] signal, double[] parameters, double pointsToConsiderEitherSideOfPeakInFWHMs, int maximumNLMFSteps)
        {
            double high             = getMax(voltages).value;
            double low              = getMin(voltages).value;
            double pointsToConsider = 0;

            System.Diagnostics.Debug.WriteLine("   " + low.ToString() + "   " + high.ToString());
            LorentzianFitter lorentzianFitter = new LorentzianFitter();

            double[][] allxypairs = new double[voltages.Length][];

            int j = 0;

            for (int i = 0; i < voltages.Length; i++)
            {
                allxypairs[i]    = new double[2];
                allxypairs[i][0] = voltages[i];
                allxypairs[i][1] = signal[i];
            }


            if (pointsToConsiderEitherSideOfPeakInFWHMs * parameters[0] < 10)
            {
                pointsToConsider = 10;
            }
            else
            {
                pointsToConsider = pointsToConsiderEitherSideOfPeakInFWHMs * parameters[0];
            }

            for (int i = 0; i < voltages.Length; i++)
            {
                if ((allxypairs[i][0] > (parameters[1] - pointsToConsider)) && (allxypairs[i][0] < (parameters[1] + pointsToConsider)))
                {
                    j++;
                }
            }

            double[] selectedvoltages = new double[j];
            double[] selectedsignal   = new double[j];


            for (int i = 0, k = 0; i < voltages.Length; i++)
            {
                if ((allxypairs[i][0] > (parameters[1] - pointsToConsider)) && (allxypairs[i][0] < (parameters[1] + pointsToConsider)))
                {
                    selectedvoltages[k] = allxypairs[i][0];
                    selectedsignal[k]   = allxypairs[i][1];
                    k++;
                }
            }
            // takes the parameters (in this order, in the double[])
            // N: background
            // Q: signal
            // c: centre
            // w: width

            dataPoint max = getMax(signal);
            dataPoint min = getMin(signal);

            lorentzianFitter.Fit(selectedvoltages, selectedsignal,
                                 new double[] { parameters[3], parameters[2], parameters[1], parameters[0] }, 0, 0, maximumNLMFSteps);

            double[] coefficients = lorentzianFitter.Parameters;

            fitFailSafe(coefficients, low, high);

            return(new double[] { coefficients[3], coefficients[2], coefficients[1], coefficients[0] }); //to be consistent with old convention.
        }