Ejemplo n.º 1
0
        public void TestBinChi2()
        {
            int npiece = 1000;
            double bw = 1.0 / npiece;
            double nsig = 10000;
            double[] edges = NP.Linspace(0,1, npiece);
            double[] x = NP.MidPoints(edges);
            double[] y = NP.Broadcast(
                (xx) =>  nsig*bw*GenericPDF.gaussian_flat(xx, 0.5, 0.1),
                x);

            PDF pdf = (v) => {
                    double xx = v[0];
                    double mu = v[1];
                    double sigma = v[2];
                    double N = v[3];
                    return N*GenericPDF.gaussian_flat(xx, mu, sigma);
                };

            double[] arg = { 0.5, 0.1, nsig };
            BinChi2 x2 = new BinChi2(pdf, edges, y);
            double chi2 = x2.Compute(arg);
            Assert.IsTrue(chi2 < 1.0);
        }
Ejemplo n.º 2
0
            /// <summary>
            /// Construct PeakFitter from initialpeakguess, histogam edges+values, 
            /// </summary>
            /// <param name="guess">Initial peak guess.</param>
            /// <param name="edges">edges of the truncated histogram</param>
            /// <param name="y">histogram value</param>
            /// <param name="sigma">Uncertainty on Y</param>
            /// <returns>PeakFitter</returns>
            public static PeakFitter FromGuess(InitialPeakGuess guess, double[] edges, double[] y, double[] sigma = null)
            {
                PeakingPDF pdf = PeakingPDF.OfInitialPeakGuess(guess);
                BinChi2 x2 = new BinChi2(pdf.Compute, edges, y, sigma);
                string[] paramnames = pdf.ParamNames(); //full paramname with x
                string[] pname = new string[paramnames.Length - 1]; //Dock off x
                for (int i = 0; i < pname.Length; i++)
                {
                    pname[i] = paramnames[i + 1];
                }
                Minuit minuit = new Minuit((FCN)(x2.Compute), pname);
                minuit.SetInitialValue("mu", guess.mu);
                minuit.SetInitialValue("sigma", guess.sigma);
                minuit.SetInitialValue("nsig", guess.nsig);
                minuit.SetInitialValue("m", guess.m);
                minuit.SetInitialValue("c", guess.c);
                minuit.SetInitialValue("nbkg", guess.nbkg);

                PeakFitter ret = new PeakFitter() { pdf = pdf, minuit = minuit, edges=edges};
                return ret;
            }