Beispiel #1
0
        /// <summary>
        /// This routine updates our frontend. All updates are performed in a threadsafe manner, as the
        /// stochastic methods can take place on a separate thread
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ReflCalc_Update(object sender, EventArgs e)
        {
            //Necessary due to the possibility of updating from a separate thread (such as stochastic fitting). Otherwise, events are fired which reset some of the values
            //below. A lock isn't necessary this isn't necessarilly a race condition
            m_isupdating = true;

            SubRough.ThreadSafeSetText(ReflCalc.GetSubRoughness.ToString());

            if (ReflCalc.ImpNormCB)
            {
                NormCorrectTB.ThreadSafeSetText(ReflCalc.NormalizationFactor.ToString());
            }

            Holdsigma.ThreadSafeChecked(ReflCalc.IsOneSigma);
            BoxCount.ThreadSafeSetText(ReflCalc.BoxCount.ToString());
            ImpNormCB.ThreadSafeChecked(ReflCalc.ImpNormCB);

            //Blank our Rho data from the previous iteration
            for (int i = 0; i < RhoArray.Count; i++)
            {
                if (!m_bUseSLD)
                {
                    RhoArray[i].ThreadSafeSetText(ReflCalc.RhoArray[i].ToString());
                }
                else
                {
                    RhoArray[i].ThreadSafeSetText((ReflCalc.RhoArray[i] / ReflCalc.SubphaseSLD).ToString());
                }

                LengthArray[i].ThreadSafeSetText(ReflCalc.LengthArray[i].ToString());
                SigmaArray[i].ThreadSafeSetText(ReflCalc.SigmaArray[i].ToString());
            }

            if (Holdsigma.Checked)
            {
                ChangeRoughnessArray();
            }

            if (m_bmodelreset)
            {
                ReflGraphing.Clear();
                ReflGraphing.LoadDatawithErrorstoGraph("Reflectivity Data", Color.Black, SymbolType.Circle, 5, ReflData.Instance.GetQData, ReflData.Instance.GetReflData);
                m_bmodelreset = false;
            }

            GreyFields();
            //Update graphs
            RhoGraphing.Pane.XAxis.Scale.Min = 0;
            RhoGraphing.Pane.XAxis.Scale.Max = ReflCalc.Z[ReflCalc.Z.Length - 1];

            ReflGraphing.LoadfromArray("modelrefl", ReflData.Instance.GetQData, ReflCalc.ReflectivityMap, System.Drawing.Color.Black, SymbolType.XCross, 4, true, string.Empty);
            RhoGraphing.LoadfromArray("Model Dependent Fit", ReflCalc.Z, ReflCalc.ElectronDensityArray, System.Drawing.Color.Turquoise, SymbolType.None, 0, true, string.Empty);
            RhoGraphing.LoadfromArray("Model Dependent Box Fit", ReflCalc.Z, ReflCalc.BoxElectronDensityArray, System.Drawing.Color.Red, SymbolType.None, 0, false, string.Empty);

            chisquaretb.ThreadSafeSetText(ReflCalc.MakeChiSquare().ToString());
            FitnessScoreTB.ThreadSafeSetText(ReflCalc.MakeFitnessScore().ToString());

            m_isupdating = false;
        }
Beispiel #2
0
        private void UpdateProfile(object sender, EventArgs e)
        {
            Zoffset.Text  = RhoCalc.ZOffset.ToString();
            SubRough.Text = RhoCalc.GetSubRoughness.ToString();

            //Update our Rho data from the previous iteration
            for (int i = 0; i < BoxRhoArray.Count; i++)
            {
                BoxRhoArray[i].Text    = RhoCalc.RhoArray[i].ToString();
                BoxSigmaArray[i].Text  = RhoCalc.SigmaArray[i].ToString();
                BoxLengthArray[i].Text = RhoCalc.LengthArray[i].ToString();
            }

            chisquaretb.ThreadSafeSetText(RhoCalc.MakeChiSquare().ToString());
            FitnessScoreTB.ThreadSafeSetText(RhoCalc.MakeFitnessScore().ToString());

            m_gRhoGraphing.LoadfromArray("Model Dependent Fit", RhoCalc.Z, RhoCalc.ElectronDensityArray, System.Drawing.Color.Turquoise, SymbolType.None, 0, true, string.Empty);
            m_gRhoGraphing.LoadfromArray("Model Dependent Box Fit", RhoCalc.Z, RhoCalc.BoxElectronDensityArray, System.Drawing.Color.Red, SymbolType.None, 0, false, string.Empty);
        }
Beispiel #3
0
        private void UpdateGraphs()
        {
            try
            {
                if (origreflfilename == string.Empty)
                {
                    return;
                }

                Color color;

                if (m_bmodelreset)
                {
                    reflgraphobject.SetGraphType(forceRQ4GraphingToolStripMenuItem.Checked, fresnelcb.Checked);

                    if (m_bmodelreset || !reflgraphobject.DataFileLoaded)
                    {
                        reflgraphobject.Clear();
                        reflgraphobject.LoadDatawithErrorstoGraph("Reflectivity Data", Color.Black, SymbolType.Circle, 5, ReflData.Instance.GetQData, ReflData.Instance.GetReflData);

                        if (rhographobject.HasCurve)
                        {
                            rhographobject.Clear();
                            rhographobject.LoadFiletoGraph(ReflData.Instance.GetWorkingDirectory + "//rho.dat", rhomodelname, "Model Independent Electron Density Fit", Color.Tomato, SymbolType.None, 0, true);
                        }
                    }
                    else
                    {
                        reflgraphobject.ClearCurves();
                    }

                    if (Refl != null)
                    {
                        reflgraphobject.LoadfromArray(modelreflname, Q, Refl, Color.Tomato, SymbolType.Square, 2, true, string.Empty);
                    }
                    else
                    {
                        string tempfile = ReflData.Instance.GetWorkingDirectory + "\\rf.dat";

                        if (File.Exists(tempfile))
                        {
                            reflgraphobject.LoadFiletoGraph(tempfile.ToString(), modelreflname, "Model Independent Reflectivity", Color.Tomato, SymbolType.Square, 2, true);
                        }
                    }

                    m_bmodelreset = false;
                }
                else
                {
                    if (colorswitch % 2 == 0)
                    {
                        color = Color.DeepSkyBlue;
                    }
                    else
                    {
                        color = Color.Tomato;
                    }


                    if (Q != null && Z != null)
                    {
                        reflgraphobject.LoadfromArray(modelreflname, Q, Refl, color, SymbolType.Triangle, 2, true, string.Empty);
                        rhographobject.LoadfromArray(rhomodelname, Z, Rho, color, SymbolType.None, 0, true, string.Empty);
                        colorswitch++;
                    }
                }

                //Update the report and internal graphs
                GraphCollection.Instance.MainReflGraph = reflgraphobject;
                GraphCollection.Instance.MainRhoGraph  = rhographobject;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Graphs and fits an Electron Density Profile against a user defined Electron Density Profile
        /// </summary>
        /// <param name="Z">Array of thickness data points</param>
        /// <param name="ERho">Electron density of the profile to be fit</param>
        /// <param name="roughness">The overall smoothing parameter found by the model independent fit</param>
        /// <param name="SupOffset">The offset in Z for the first box</param>
        /// <param name="subsld">The subphase SLD</param>
        /// <param name="supsld">The superphase SLD</param>
        public Rhomodeling(double[] Z, double[] ERho, double roughness, string SupOffset, string subsld, string supsld)
        {
            InitializeComponent();
            RhoCalc = new RhoFit(Z, ERho);

            BoxSigmaArray  = new List <TextBox>(6);
            BoxLengthArray = new List <TextBox>(6);
            BoxRhoArray    = new List <TextBox>(6);

            this.Text = "Profile Modeling";

            //Setup variables
            if (roughness == 0)
            {
                roughness = 3.0;
            }

            RhoCalc.GetSubRoughness = roughness;
            SubRough.Text           = roughness.ToString();
            Zoffset.Text            = SupOffset.ToString();

            SubphaseSLD.Text = subsld;
            SupSLDTB.Text    = supsld;

            //Set default array values
            if (Properties.Settings.Default.UseSLDSingleSession == false)
            {
                Rho2.Text = Rho1.Text = (1.1).ToString();
            }
            else
            {
                Rho2.Text = Rho1.Text = (1.3 * double.Parse(subsld)).ToString();
            }

            Sigma2.Text   = Sigma1.Text = (3.25).ToString();
            LLength1.Text = LLength2.Text = (15.1).ToString();


            //Initialize the arrays
            MakeArrays();

            if (Z == null)
            {
                Report_btn.Enabled = UndoFit.Enabled = LevenbergFit.Enabled = false;
            }

            //Setup the Graph
            m_gRhoGraphing        = new Graphing(string.Empty);
            m_gRhoGraphing.SubSLD = double.Parse(subsld);
            m_gRhoGraphing.UseSLD = Properties.Settings.Default.UseSLDSingleSession;

            if (Properties.Settings.Default.UseSLDSingleSession == false)
            {
                m_gRhoGraphing.CreateGraph(RhoGraph, "Electron Density Profile", "Z", "Normalized Electron Density", AxisType.Linear);
                RhoLabel.Text = "Normalized Rho";
            }
            else
            {
                m_gRhoGraphing.CreateGraph(RhoGraph, "SLD Profile", "Z", "SLD", AxisType.Linear);
                RhoLabel.Text = "SLD";
            }

            m_gRhoGraphing.SetGraphType(false, false);

            if (Z != null)
            {
                m_gRhoGraphing.LoadfromArray("Model Independent Fit", Z, ERho, System.Drawing.Color.Black, SymbolType.None, 0, true, string.Empty);
            }

            ChangeRoughnessArray();
            GreyFields();

            //Subscribe to the event that notifies us to update the frontend
            RhoCalc.Update += new BoxReflFitBase.UpdateProfileHandler(UpdateProfile);

            //Create the electron density graph
            MakeED();
        }