public void TestCachedNormalized() { PDF linear = (v) => { double x = v[0]; double m = v[1]; double c = v[2]; return m * x + c; }; CachedNormalized cnorm = new CachedNormalized(linear, 0, 1); F3 normlin = (x, m, c) => (m * x + c) / (m / 2 + c); double[] xmc = { 1, 2, 3 }; Assert.AreEqual(normlin(1, 2, 3), cnorm.Compute(xmc)); }
public PeakingPDF(double lowerbound, double upperbound, int pieces = 2000) { PDF gauss = GenericPDF.gaussian; PDF linear = GenericPDF.linear; this.bkg = new CachedNormalized(linear, lowerbound, upperbound, pieces); this.peak = new CachedNormalized(gauss, lowerbound, upperbound, pieces); }
public void TestPeakingPDF() { double lower = 0.0; double upper = 1.0; double x = 0.5; double mu = 0.5; double sigma = 0.1; double nsig=10000; double m = 0; double c = 1; double nbkg = 2000; PeakingPDF pdf = new PeakingPDF(0, 1); double[] arg = { x, mu, sigma, nsig, m, c, nbkg }; Console.WriteLine(pdf.Compute(arg)); CachedNormalized peak = new CachedNormalized(GenericPDF.gaussian, lower, upper, 10000); CachedNormalized bkg = new CachedNormalized(GenericPDF.linear, lower, upper, 10000); double expected = nsig * peak.Compute(new double[]{x, mu, sigma}) + nbkg * bkg.Compute(new double[]{x, m, c}); Assert.AreEqual(expected, pdf.Compute(arg), 1e-7); }