/// <summary> /// Returns an array[h.XAxis.Bins]; ignoring extra bins. //// protected double[] ToArrayHeights(IHistogram1D h) { int xBins = h.XAxis.Bins; double[] array = new double[xBins]; for (int j = xBins; --j >= 0;) { array[j] = h.BinHeight(j); } return(array); }
private static void writeAsXML(IHistogram1D h, String filename) { try { using (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("<data1d>"); writer.WriteLine("<bins1d title=\"" + h.Title + "\">"); for (int i = 0; i < h.XAxis.Bins; i++) { writer.WriteLine(h.BinEntries(i) + "," + h.BinError(i)); } writer.WriteLine("</bins1d>"); 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.WriteLine("<statistics>"); writer.WriteLine("<statistic name=\"Entries\" value=\"" + h.Entries + "\"/>"); writer.WriteLine("<statistic name=\"Underflow\" value=\"" + h.BinEntries(HistogramType.UNDERFLOW.ToInt()) + "\"/>"); writer.WriteLine("<statistic name=\"Overflow\" value=\"" + h.BinEntries(HistogramType.OVERFLOW.ToInt()) + "\"/>"); if (!Double.IsNaN(h.Mean)) { writer.WriteLine("<statistic name=\"Mean\" value=\"" + h.Mean + "\"/>"); } if (!Double.IsNaN(h.Rms)) { writer.WriteLine("<statistic name=\"RMS\" value=\"" + h.Rms + "\"/>"); } writer.WriteLine("</statistics>"); writer.WriteLine("</data1d>"); writer.WriteLine("</dataArea>"); writer.WriteLine("</plot>"); writer.WriteLine("</plotML>"); writer.Close(); } } catch (IOException x) { using (StreamWriter writer = new StreamWriter(filename)) { writer.Write(x.StackTrace); } } }
public int MaxBin(IHistogram1D h) { int maxBin = -1; double maxValue = Double.MinValue; for (int i = h.XAxis.Bins; --i >= 0;) { double value = h.BinHeight(i); if (value > maxValue) { maxValue = value; maxBin = i; } } return(maxBin); }
/// <summary> /// Returns a string representation of the given argument. //// public String ToString(IHistogram1D h) { String columnAxisName = null; //"X"; String rowAxisName = null; Hep.Aida.Bin.BinFunction1D[] aggr = null; //{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"; //"\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 + " Mean=" + Form(f, h.Mean) + ", Rms=" + Form(f, h.Rms) + sep + " MinBinHeight=" + Form(f, h.BinHeight(minMaxBins[0])) + ", MaxBinHeight=" + Form(f, h.BinHeight(minMaxBins[1])) + sep + " Axis: " + "Bins=" + Form(f, h.XAxis.Bins) + ", Min=" + Form(f, h.XAxis.LowerEdge) + ", Max=" + Form(f, h.XAxis.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[] { "Data" }; Cern.Colt.Matrix.DoubleMatrix2D heights = new DenseDoubleMatrix2D(1, h.XAxis.Bins); heights.ViewRow(0).Assign(ToArrayHeights(h)); //Cern.Colt.Matrix.DoubleMatrix2D errors = new Cern.Colt.Matrix.DenseDoubleMatrix2D(1,h.XAxis.Bins); //errors.ViewRow(0).Assign(toArrayErrors(h)); 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); */ }
private static void writeAsXML(IHistogram1D 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(); } */ } }
/// <summary> /// Returns a XML representation of the given argument. //// public String ToXML(IHistogram1D h) { StringBuilder buf = new StringBuilder(); String sep = "\n\r"; //System.getProperty("line.separator"); buf.Append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>"); buf.Append(sep); buf.Append("<!DOCTYPE plotML SYSTEM \"plotML.dtd\">"); buf.Append(sep); buf.Append("<plotML>"); buf.Append(sep); buf.Append("<plot>"); buf.Append(sep); buf.Append("<dataArea>"); buf.Append(sep); buf.Append("<data1d>"); buf.Append(sep); buf.Append("<bins1d title=\"" + h.Title + "\">"); buf.Append(sep); for (int i = 0; i < h.XAxis.Bins; i++) { buf.Append(h.BinEntries(i) + "," + h.BinError(i)); buf.Append(sep); } buf.Append("</bins1d>"); buf.Append(sep); buf.Append("<binnedDataAxisAttributes type=\"double\" axis=\"x0\""); buf.Append(" min=\"" + h.XAxis.LowerEdge + "\""); buf.Append(" max=\"" + h.XAxis.UpperEdge + "\""); buf.Append(" numberOfBins=\"" + h.XAxis.Bins + "\""); buf.Append("/>"); buf.Append(sep); buf.Append("<statistics>"); buf.Append(sep); buf.Append("<statistic name=\"Entries\" value=\"" + h.Entries + "\"/>"); buf.Append(sep); buf.Append("<statistic name=\"Underflow\" value=\"" + h.BinEntries(int.Parse(HistogramType.UNDERFLOW.ToString())) + "\"/>"); buf.Append(sep); buf.Append("<statistic name=\"Overflow\" value=\"" + h.BinEntries(int.Parse(HistogramType.OVERFLOW.ToString())) + "\"/>"); buf.Append(sep); if (!Double.IsNaN(h.Mean)) { buf.Append("<statistic name=\"Mean\" value=\"" + h.Mean + "\"/>"); buf.Append(sep); } if (!Double.IsNaN(h.Rms)) { buf.Append("<statistic name=\"RMS\" value=\"" + h.Rms + "\"/>"); buf.Append(sep); } buf.Append("</statistics>"); buf.Append(sep); buf.Append("</data1d>"); buf.Append(sep); buf.Append("</dataArea>"); buf.Append(sep); buf.Append("</plot>"); buf.Append(sep); buf.Append("</plotML>"); buf.Append(sep); return(buf.ToString()); }