/// <summary> /// Returns an array[h.XAxis.Bins]; ignoring extra bins. //// protected double[] ToArrayErrors(IHistogram1D h) { int xBins = h.XAxis.Bins; double[] array = new double[xBins]; for (int j = xBins; --j >= 0;) { array[j] = h.BinError(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); } } }
/// <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()); }