Example #1
0
        /// <summary>
        /// Fill a 2D plot in the future
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <param name="source"></param>
        /// <param name="plotID"></param>
        /// <param name="plotTitle"></param>
        /// <param name="xNBins"></param>
        /// <param name="xLowBin"></param>
        /// <param name="xHighBin"></param>
        /// <param name="yNBins"></param>
        /// <param name="yLowBin"></param>
        /// <param name="yHighBin"></param>
        /// <param name="xGetter">A lambda that calculates the X value for the 2D histogram for each item in the sequence</param>
        /// <param name="yGetter">A lambda that calculates the Y value for the 2D histogram for each item in the sequence</param>
        /// <param name="weight"></param>
        /// <returns></returns>
        public static IFutureValue <ROOTNET.NTH2F> FuturePlot <TSource>
        (
            this IQueryable <TSource> source,
            string plotID, string plotTitle,
            int xNBins, double xLowBin, double xHighBin,
            Expression <Func <TSource, double> > xGetter,
            int yNBins, double yLowBin, double yHighBin,
            Expression <Func <TSource, double> > yGetter,
            Expression <Func <TSource, double> > weight = null
        )
        {
            if (weight == null)
            {
                Expression <Func <TSource, double> > constWeight = s => 1.0;
                weight = constWeight;
            }
            var hParameter = Expression.Parameter(typeof(ROOTNET.NTH2F), "h");
            var vParameter = Expression.Parameter(typeof(TSource), "v");

            var callXGetter = Expression.Invoke(xGetter, vParameter);
            var callYGetter = Expression.Invoke(yGetter, vParameter);
            var callWeight  = Expression.Invoke(weight, vParameter);

            var fillMethod = typeof(ROOTNET.NTH2F).GetMethod("Fill", new[] { typeof(double), typeof(double), typeof(double) });
            var callFill   = Expression.Call(hParameter, fillMethod, callXGetter, callYGetter, callWeight);

            var lambda       = Expression.Lambda <Action <ROOTNET.NTH2F, TSource> >(callFill, hParameter, vParameter);
            var interfaceobj = new ROOTNET.NTH2F(plotID, plotTitle.ReplaceLatexStrings(), xNBins, xLowBin, xHighBin, yNBins, yLowBin, yHighBin);

            ConfigureHisto(interfaceobj);
            return(source.FutureApplyToObject(interfaceobj, lambda));
        }
        public void AsEffOneBinPlotReverse()
        {
            var h = new ROOTNET.NTH2F("hi", "there", 1, 0.0, 10.0, 1, 0.0, 10.0);

            h.SetBinContent(1, 1, 10.0);

            var r = PlotOperations.asEfficiency(new RootContext(), h, false, false);

            Assert.AreEqual(1.0, r.GetBinContent(1, 1));
        }
        public void TwoBinsOneRowBothFilled()
        {
            var h = new ROOTNET.NTH2F("hi", "there", 2, 0.0, 10.0, 1, 0.0, 10.0);

            h.SetBinContent(1, 1, 10.0);
            h.SetBinContent(2, 1, 10.0);

            var r = PlotOperations.asEfficiency(new RootContext(), h, true, true);

            Assert.AreEqual(1.0, r.GetBinContent(1, 1));
            Assert.AreEqual(0.5, r.GetBinContent(2, 1));
        }
        public void FourBinsOneRowBothFilledReverse()
        {
            var h = new ROOTNET.NTH2F("hi", "there", 4, 0.0, 10.0, 1, 0.0, 10.0);

            h.SetBinContent(1, 1, 10.0);
            h.SetBinContent(2, 1, 10.0);
            h.SetBinContent(3, 1, 10.0);
            h.SetBinContent(4, 1, 10.0);

            var r = PlotOperations.asEfficiency(new RootContext(), h, false, true);

            Assert.AreEqual(0.25, r.GetBinContent(1, 1));
            Assert.AreEqual(0.50, r.GetBinContent(2, 1));
            Assert.AreEqual(0.75, r.GetBinContent(3, 1));
            Assert.AreEqual(1.0, r.GetBinContent(4, 1));
        }