Exemplo n.º 1
0
        /// <summary>
        /// Create a asymetric graph with a pave - upper and lower, from data (lines) in three histograms
        /// with a central value.
        /// </summary>
        /// <param name="central">The central line</param>
        /// <param name="upper">The upper line</param>
        /// <param name="lower">The lower line</param>
        /// <returns></returns>
        public static ROOTNET.NTGraph pave(IScopeContext ctx, ROOTNET.NTH1 central, ROOTNET.NTH1 upper, ROOTNET.NTH1 lower, IDictionary <object, object> options = null)
        {
            // Make sure we are ready to go!
            if (central.NbinsX != upper.NbinsX ||
                central.NbinsX != lower.NbinsX)
            {
                throw new ArgumentException($"Can't make pave with (central: {central.Name}, upper: {upper.Name}, lower: {lower.Name}) as they don't all have the same binning!");
            }

            // Parse the options, if there are any!
            var minXValue = central.GetBinLowEdge(1);

            foreach (var opt in options.Keys.Cast <string>())
            {
                if (opt == "xmin")
                {
                    minXValue = (double)options[opt];
                }
                else
                {
                    throw new ArgumentException($"pave: Illegial option '{opt}' - only know xmin for creating a pave.");
                }
            }

            // loop through each point and set it.
            var points = new List <Tuple <double, double, double, double> >();

            for (int idx = 0; idx < central.NbinsX; idx++)
            {
                if (central.GetBinCenter(idx + 1) >= minXValue)
                {
                    points.Add(Tuple.Create(central.GetBinCenter(idx + 1),
                                            central.GetBinContent(idx + 1),
                                            upper.GetBinContent(idx + 1) - central.GetBinContent(idx + 1),
                                            central.GetBinContent(idx + 1) - lower.GetBinContent(idx + 1)));
                }
            }

            // Create the graph, use the central object to setup meta data.
            // Don't copy tags as what this pave is may be different from what the original
            // histograms were.
            var g = new ROOTNET.NTGraphAsymmErrors(points.Count);

            g.Name  = $"{central.Name}_g";
            g.Title = central.Title;

            for (int i_bin = 0; i_bin < points.Count; i_bin++)
            {
                var val = points[i_bin];
                g.SetPoint(i_bin, val.Item1, val.Item2);
                g.SetPointEYhigh(i_bin, val.Item3);
                g.SetPointEYlow(i_bin, val.Item4);
            }

            // Done!
            return(g);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Convert a histogram to a graph, simply.
        /// </summary>
        /// <param name="histo"></param>
        /// <returns></returns>
        public static ROOTNET.NTGraph ConvertHistoToGraph(this ROOTNET.NTH1 histo, IScopeContext ctx)
        {
            var g = new ROOTNET.NTGraph(histo.NbinsX);

            g.FillColor = 0; // Make sure the background is white

            // Copy meta-data.
            Tags.CopyTags(ctx, histo, g);
            g.Title     = histo.Title;
            g.Name      = $"{histo.Name}_g";
            g.LineWidth = histo.LineWidth;
            g.LineColor = histo.LineColor;
            g.LineStyle = histo.LineStyle;

            // And points.
            for (int i = 0; i < histo.NbinsX; i++)
            {
                g.SetPoint(i, histo.GetBinCenter(i + 1), histo.GetBinContent(i + 1));
            }

            return(g);
        }
Exemplo n.º 3
0
 public static ROOTNET.NTGraph asGraph(IScopeContext ctx, ROOTNET.NTH1 h)
 {
     return(h.ConvertHistoToGraph(ctx));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Create a plot context given a single plot.
 /// </summary>
 /// <param name="plot"></param>
 /// <returns></returns>
 public static PlotContext plot(ROOTNET.NTH1 plot)
 {
     return new PlotContext(new ROOTNET.NTH1[] { plot });
 }