コード例 #1
0
 private static void writeAsXML(IHistogram2D h, String filename)
 {
     try
     {
         StreamWriter writer = new StreamWriter(filename);
         writer.WriteLine("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>");
         writer.WriteLine("<!DOCTYPE plotML SYSTEM \"plotML.dtd\">");
         writer.WriteLine("<plotML>");
         writer.WriteLine("<plot>");
         writer.WriteLine("<dataArea>");
         writer.WriteLine("<data2d type=\"xxx\">");
         writer.WriteLine("<bins2d title=\"" + h.Title + "\" xSize=\"" + h.XAxis.Bins + "\" ySize=\"" + h.YAxis.Bins + "\">");
         for (int i = 0; i < h.XAxis.Bins; i++)
         {
             for (int j = 0; j < h.YAxis.Bins; j++)
             {
                 writer.WriteLine(h.BinEntries(i, j) + "," + h.BinError(i, j));
             }
         }
         writer.WriteLine("</bins2d>");
         writer.Write("<binnedDataAxisAttributes type=\"double\" axis=\"x0\"");
         writer.Write(" min=\"" + h.XAxis.LowerEdge + "\"");
         writer.Write(" max=\"" + h.XAxis.UpperEdge + "\"");
         writer.Write(" numberOfBins=\"" + h.XAxis.Bins + "\"");
         writer.WriteLine("/>");
         writer.Write("<binnedDataAxisAttributes type=\"double\" axis=\"y0\"");
         writer.Write(" min=\"" + h.YAxis.LowerEdge + "\"");
         writer.Write(" max=\"" + h.YAxis.UpperEdge + "\"");
         writer.Write(" numberOfBins=\"" + h.YAxis.Bins + "\"");
         writer.WriteLine("/>");
         //writer.WriteLine("<statistics>");
         //writer.WriteLine("<statistic name=\"Entries\" value=\""+h.entries()+"\"/>");
         //writer.WriteLine("<statistic name=\"MeanX\" value=\""+h.meanX()+"\"/>");
         //writer.WriteLine("<statistic name=\"RmsX\" value=\""+h.rmsX()+"\"/>");
         //writer.WriteLine("<statistic name=\"MeanY\" value=\""+h.meanY()+"\"/>");
         //writer.WriteLine("<statistic name=\"RmsY\" value=\""+h.rmsY()+"\"/>");
         //writer.WriteLine("</statistics>");
         writer.WriteLine("</data2d>");
         writer.WriteLine("</dataArea>");
         writer.WriteLine("</plot>");
         writer.WriteLine("</plotML>");
         writer.Close();
     }
     catch (IOException x)
     {
         using (StreamWriter writer = new StreamWriter(filename))
         {
             writer.Write(x.StackTrace);
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// Returns an array[h.XAxis.Bins][h.YAxis.Bins]; ignoring extra bins.
        ////
        protected double[][] ToArrayErrors(IHistogram2D h)
        {
            int xBins = h.XAxis.Bins;
            int yBins = h.YAxis.Bins;

            double[][] array = new double[xBins][];
            for (int i = yBins; --i >= 0;)
            {
                array[i] = new double[yBins];
                for (int j = xBins; --j >= 0;)
                {
                    array[j][i] = h.BinError(j, i);
                }
            }
            return(array);
        }
コード例 #3
0
        /// <summary>
        /// Returns an array[h.XAxis.Bins][h.YAxis.Bins]; ignoring extra bins.
        ////
        protected double[][] ToArrayHeights(IHistogram2D h)
        {
            int xBins = h.XAxis.Bins;
            int yBins = h.YAxis.Bins;
            //double[][] array = new double[xBins][];
            var array = (new double[xBins, yBins]).ToJagged();

            for (int i = yBins; --i >= 0;)
            {
                //array[i] = new double[yBins];
                for (int j = xBins; --j >= 0;)
                {
                    array[j][i] = h.BinHeight(j, i);
                }
            }
            return(array);
        }
コード例 #4
0
        private static void writeAsXML(IHistogram2D h, String filename)
        {
            using (StreamWriter writer = new StreamWriter(filename))
            {
                writer.WriteLine(new Converter().ToString(h));
                //System.out.println(new Converter().toXML(h));

                /*
                 * try
                 * {
                 *  PrintWriter out = new PrintWriter(new FileWriter(filename));
                 *  out.println(new Converter().toXML(h));
                 *  out.close();
                 * }
                 * catch (IOException x) { x.printStackTrace(); }
                 */
            }
        }
コード例 #5
0
        /// <summary>
        /// Returns a XML representation of the given argument.
        ////
        public String ToXML(IHistogram2D h)
        {
            StringBuilder o   = new StringBuilder();
            String        sep = "\n\r"; //System.getProperty("line.separator");

            o.Append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>"); o.Append(sep);
            o.Append("<!DOCTYPE plotML SYSTEM \"plotML.dtd\">"); o.Append(sep);
            o.Append("<plotML>"); o.Append(sep);
            o.Append("<plot>"); o.Append(sep);
            o.Append("<dataArea>"); o.Append(sep);
            o.Append("<data2d type=\"xxx\">"); o.Append(sep);
            o.Append("<bins2d title=\"" + h.Title + "\" xSize=\"" + h.XAxis.Bins + "\" ySize=\"" + h.YAxis.Bins + "\">"); o.Append(sep);
            for (int i = 0; i < h.XAxis.Bins; i++)
            {
                for (int j = 0; j < h.YAxis.Bins; j++)
                {
                    o.Append(h.BinEntries(i, j) + "," + h.BinError(i, j)); o.Append(sep);
                }
            }
            o.Append("</bins2d>"); o.Append(sep);
            o.Append("<binnedDataAxisAttributes type=\"double\" axis=\"x0\"");
            o.Append(" min=\"" + h.XAxis.LowerEdge + "\"");
            o.Append(" max=\"" + h.XAxis.UpperEdge + "\"");
            o.Append(" numberOfBins=\"" + h.XAxis.Bins + "\"");
            o.Append("/>"); o.Append(sep);
            o.Append("<binnedDataAxisAttributes type=\"double\" axis=\"y0\"");
            o.Append(" min=\"" + h.YAxis.LowerEdge + "\"");
            o.Append(" max=\"" + h.YAxis.UpperEdge + "\"");
            o.Append(" numberOfBins=\"" + h.YAxis.Bins + "\"");
            o.Append("/>"); o.Append(sep);
            //o.Append("<statistics>"); o.Append(sep);
            //o.Append("<statistic name=\"Entries\" value=\""+h.Entries+"\"/>"); o.Append(sep);
            //o.Append("<statistic name=\"MeanX\" value=\""+h.MeanX+"\"/>"); o.Append(sep);
            //o.Append("<statistic name=\"RmsX\" value=\""+h.RmsX+"\"/>"); o.Append(sep);
            //o.Append("<statistic name=\"MeanY\" value=\""+h.MeanY+"\"/>"); o.Append(sep);
            //o.Append("<statistic name=\"RmsY\" value=\""+h.RmsY+"\"/>"); o.Append(sep);
            //o.Append("</statistics>"); o.Append(sep);
            o.Append("</data2d>"); o.Append(sep);
            o.Append("</dataArea>"); o.Append(sep);
            o.Append("</plot>"); o.Append(sep);
            o.Append("</plotML>"); o.Append(sep);
            return(o.ToString());
        }
コード例 #6
0
ファイル: Utility.cs プロジェクト: cobaltblueocean/Colt.NET
        /// <summary>
        /// Returns the indexY of the in-range bin containing the MaxBinHeight.
        /// </summary>
        /// <param name="h"></param>
        /// <returns></returns>
        public int MaxBinY(IHistogram2D h)
        {
            double maxValue = Double.MinValue;
            int    maxBinX  = -1;
            int    maxBinY  = -1;

            for (int i = h.XAxis.Bins; --i >= 0;)
            {
                for (int j = h.YAxis.Bins; --j >= 0;)
                {
                    double value = h.BinHeight(i, j);
                    if (value > maxValue)
                    {
                        maxValue = value;
                        maxBinX  = i;
                        maxBinY  = j;
                    }
                }
            }
            return(maxBinY);
        }
コード例 #7
0
        /// <summary>
        /// Returns a string representation of the given argument.
        ////
        public String ToString(IHistogram2D h)
        {
            String columnAxisName = "X";
            String rowAxisName    = "Y";

            Hep.Aida.Bin.BinFunction1D[] aggr = { Hep.Aida.Bin.BinFunctions1D.Sum };
            String format = "G"; // "%G"

            //String format = "%1.2G";

            Cern.Colt.Matrix.Former f = new Cern.Colt.Matrix.Implementation.FormerFactory().Create(format);
            String sep = "\n\r"; //System.getProperty("line.separator");

            int[]  minMaxBins = h.MinMaxBins;
            String title      = h.Title + ":" + sep +
                                "   Entries=" + Form(f, h.Entries) + ", ExtraEntries=" + Form(f, h.ExtraEntries) + sep +
                                "   MeanX=" + Form(f, h.MeanX) + ", RmsX=" + Form(f, h.RmsX) + sep +
                                "   MeanY=" + Form(f, h.MeanY) + ", RmsY=" + Form(f, h.RmsX) + sep +
                                "   MinBinHeight=" + Form(f, h.BinHeight(minMaxBins[0], minMaxBins[1])) + ", MaxBinHeight=" + Form(f, h.BinHeight(minMaxBins[2], minMaxBins[3])) + sep +

                                "   xAxis: " +
                                "Bins=" + Form(f, h.XAxis.Bins) +
                                ", Min=" + Form(f, h.XAxis.LowerEdge) +
                                ", Max=" + Form(f, h.XAxis.UpperEdge) + sep +

                                "   yAxis: " +
                                "Bins=" + Form(f, h.YAxis.Bins) +
                                ", Min=" + Form(f, h.YAxis.LowerEdge) +
                                ", Max=" + Form(f, h.YAxis.UpperEdge);

            String[] xEdges = new String[h.XAxis.Bins];
            for (int i = 0; i < h.XAxis.Bins; i++)
            {
                xEdges[i] = Form(f, h.XAxis.BinLowerEdge(i));
            }

            String[] yEdges = new String[h.YAxis.Bins];
            for (int i = 0; i < h.YAxis.Bins; i++)
            {
                yEdges[i] = Form(f, h.YAxis.BinLowerEdge(i));
            }
            new List <Object>(yEdges).Reverse(); // keep coordd system

            Cern.Colt.Matrix.DoubleMatrix2D heights = new DenseDoubleMatrix2D(ToArrayHeights(h));
            heights = heights.ViewDice().ViewRowFlip(); // keep the histo coordd system
                                                        //heights = heights.ViewPart(1,1,heights.Rows()-2,heights.columns()-2); // ignore under&overflows

            //Cern.Colt.Matrix.DoubleMatrix2D errors = new Cern.Colt.Matrix.DenseDoubleMatrix2D(toArrayErrors(h));
            //errors = errors.ViewDice().ViewRowFlip(); // keep the histo coord system
            ////errors = errors.ViewPart(1,1,errors.Rows()-2,errors.columns()-2); // ignore under&overflows

            return(title + sep +
                   "Heights:" + sep +
                   new Formatter().ToTitleString(
                       heights, yEdges, xEdges, rowAxisName, columnAxisName, null, aggr));

            /*
             + sep +
             +          "Errors:" + sep +
             +          new Cern.Colt.Matrix.doublealgo.Formatter().ToTitleString(
             +                  errors,yEdges,xEdges,rowAxisName,columnAxisName,null,aggr);
             */
        }