Пример #1
0
 private void PlotLikelihood(string text, NumericalTools.Likelihood lk)
 {
     if (lk == null)
     {
         Image im = pbLkDisplay.Image;
         Graphics g = Graphics.FromImage(im);
         g.FillRectangle(new SolidBrush(Color.White), 0, 0, im.Width, im.Height);
         g.DrawString("Likelihood not available - press Compute", new Font("Lucida", 10), new SolidBrush(Color.Black), 0, 0);
         pbLkDisplay.Refresh();
     }
     else
     {
         Image im = pbLkDisplay.Image;
         Graphics g = Graphics.FromImage(im);
         g.FillRectangle(new SolidBrush(Color.White), 0, 0, im.Width, im.Height);
         double[] p = new double[(int)Math.Floor((lk.MaxBound(0) - lk.MinBound(0)) / 0.05 + 1.0)];
         double[] logl = new double[p.Length];
         int i;                                
         for (i = 0; i < p.Length; i++)
         {
             p[i] = lk.MinBound(0) + i * 0.05;
             logl[i] = lk.LogValue(p[i]);
         }
         NumericalTools.Plot pl = new NumericalTools.Plot();
         pl.VecX = p;
         pl.VecY = logl;
         double dummy = 0.0;                
         double miny = 0.0, maxy = 0.0;
         NumericalTools.Fitting.FindStatistics(logl, ref maxy, ref miny, ref dummy, ref dummy);
         maxy += 0.2 * (maxy - miny);
         pl.JoinPenThickness = 2;
         pl.MinX = lk.MinBound(0) - 0.05;
         pl.MaxX = lk.MaxBound(0) + 0.05;
         pl.SetXDefaultLimits = false;
         pl.MinY = miny;
         pl.MaxY = maxy;
         pl.SetYDefaultLimits = false;
         pl.XTitle = "P";
         pl.YTitle = text;
         pl.LabelFont = new Font("Lucida", 10);
         pl.PanelFont = new Font("Lucida", 10);
         pl.PanelY = 3;
         pl.Scatter(g, im.Width, im.Height);
         pbLkDisplay.Refresh();
     }
 }
Пример #2
0
 private void btnCompute_Click(object sender, EventArgs e)
 {
     if (clSlopeSets.CheckedItems.Count < 1)
     {
         MessageBox.Show("At least one data set must be enabled.", "Input error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         return;
     }
     NumericalTools.Likelihood[] lk = new NumericalTools.Likelihood[clSlopeSets.CheckedItems.Count];
     int i;
     for (i = 0; i < clSlopeSets.CheckedItems.Count; i++)
     {
         FitSet fs = (FitSet)clSlopeSets.CheckedItems[i];
         if (fs.Likelihood == null)
             try
             {
                 MCSLikelihood.ProcessData(fs.Tracks, out fs.Likelihood);
             }
             catch (Exception x)
             {
                 MessageBox.Show("Error computing likelihood for set \"" + fs.ToString() + "\":\r\n" + x.Message, "Computation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 return;
             }
         lk[i] = fs.Likelihood;
     }
     Likelihood = null;
     txtResults.Text = "";
     try
     {
         Likelihood = new NumericalTools.OneParamLogLikelihood(0.05, lk);
         string t = Likelihood.Best(0).ToString("F2", System.Globalization.CultureInfo.InvariantCulture) + ";";
         double cl = ((SySal.Processing.MCSLikelihood.Configuration)MCSLikelihood.Config).ConfidenceLevel;
         double[] bounds = Likelihood.ConfidenceRegions(0, cl);                
         for (i = 0; i < bounds.Length; i += 2)
             t += " [" + bounds[i].ToString("F2", System.Globalization.CultureInfo.InvariantCulture) + "," + bounds[i + 1].ToString("F2", System.Globalization.CultureInfo.InvariantCulture) + "]";
         t += "; " + cl.ToString("F2", System.Globalization.CultureInfo.InvariantCulture);
         txtResults.Text = t;
     }
     catch (Exception x)
     {
         MessageBox.Show("Error computing combined likelihood:\r\n" + x.Message, "Computation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     PlotLikelihood("LogL (combined)", Likelihood);
 }
Пример #3
0
        /// <summary>
        /// Computes the momentum and confidence limits using positions and slopes provided.
        /// </summary>
        /// <param name="data">the position and slopes of the track (even Z-unordered).</param>
        /// <param name="likelihood">the output variable that will contain the likelihood function.</param>
        /// <returns>the momentum and confidence limits.</returns>
        public MomentumResult ProcessData(SySal.Tracking.MIPEmulsionTrackInfo[] data, out NumericalTools.Likelihood likelihood)
        {
            MomentumResult myResult = new MomentumResult();
            //ordiniamo gli elementi della geometria e dei dati inseriti per z
            Geometry gm = C.Geometry;

            data = orderElementData(data);

            //Controllo che la traccia sia contenuta in tutto il brick
            if (data[0].Intercept.Z <gm.Layers[0].ZMin || data[data.Length - 1].Intercept.Z> gm.Layers[gm.Layers.Length - 1].ZMin)
            {
                throw new Exception("Data span a Z interval that exceeds the geometry bounds.");
            }

            //Calcolo gli scattering ad ogni step e li scrivo nel file di dump se c'è!!
            scattDifference[] scatDif = calcScattDiff(gm, data);
            if (m_tkDumpFile != null)
            {
                writeInFileTK(scatDif);
            }

            //calcolo le differenze
            ArrayList resultDiff        = new ArrayList();
            ArrayList resultDiffL       = new ArrayList();
            double    myRadiationLength = C.MinimumRadiationLengths;

            resultDiff  = angularDifference(data, scatDif, myRadiationLength);
            resultDiffL = angularDifferenceL(data, scatDif, myRadiationLength);
            if (resultDiff.Count == 0)
            {
                throw new Exception("No slope difference available for computation.");
            }
            if (m_angularDiffDumpFile != null)
            {
                writeInFileAD(resultDiff);
            }

            //Calcolo elementi della matrice di covarianza e li scrivo nel file di dump se c'è!!
            ArrayList matrixFinal = new ArrayList();

            matrixFinal = covMatrix(resultDiff, scatDif);
            if (m_cvDumpFile != null)
            {
                writeInFileCV(matrixFinal);
            }

            //Calcolo la probabilità totale e li scrivo nel file di dump se c'è!!
            int maxIndex = 0;

            ProbMomentum[] finalData = totalProbability(resultDiff, matrixFinal, C.MinimumMomentum, C.MaximumMomentum, C.MomentumStep, ref maxIndex);
            if (m_lkDumpFile != null)
            {
                writeInFileLK(finalData);
            }

            //Calcolo i limiti di confidenza
            double maxLike = finalData[maxIndex].probTot;
            double myCutLike;

            myCutLike = cutLike(maxLike);
            limit myLimit;

            myLimit = limitCalculation(finalData, myCutLike, maxIndex);

            //Scrivo i risultati
            myResult.Value           = finalData[maxIndex].momValue;
            myResult.LowerBound      = myLimit.lwLimit;
            myResult.UpperBound      = myLimit.upLimit;
            myResult.ConfidenceLevel = 0.90;

            double[] lkval = new double[finalData.Length];
            int      i;

            for (i = 0; i < lkval.Length; i++)
            {
                lkval[i] = finalData[i].probTot;
            }
            likelihood = new NumericalTools.OneParamLogLikelihood(finalData[0].momValue, finalData[finalData.Length - 1].momValue, lkval, "P");
            return(myResult);

            /*
             * finalData = totalProbability(resultDiffL, matrixFinal, C.MinimumMomentum, C.MaximumMomentum, C.MomentumStep, ref maxIndex);
             * for (i = 0; i < lkval.Length; i++)
             *  lkval[i] = finalData[i].probTot;
             * likelihood = new NumericalTools.OneParamLogLikelihood(C.MomentumStep, likelihood, new NumericalTools.OneParamLogLikelihood(finalData[0].momValue, finalData[finalData.Length - 1].momValue, lkval, "P"));
             * myResult.Value = likelihood.Best(0);
             * double[] cr = likelihood.ConfidenceRegions(0, C.ConfidenceLevel);
             * myResult.LowerBound = cr[0];
             * myResult.UpperBound = cr[1];
             * return myResult;
             */
        }
Пример #4
0
 public FitSet(SySal.Tracking.MIPEmulsionTrackInfo[] tks, TrackBrowser src)
 {
     Tracks = tks;
     Source = src;               
     Likelihood = null;
 }
Пример #5
0
 /// <summary>
 /// Computes the momentum and confidence limits using positions and slopes provided.
 /// </summary>
 /// <param name="data">the position and slopes of the track (even Z-unordered).</param>
 /// <returns>the momentum and confidence limits.</returns>
 public MomentumResult ProcessData(SySal.Tracking.MIPEmulsionTrackInfo[] data)
 {
     NumericalTools.Likelihood lk = null;
     return(ProcessData(data, out lk));
 }