public H2D() { offset = new MultiIndex(xAxis.getNBins(), yAxis.getNBins()); hBuffer = new double[offset.getArraySize()]; this.attr.getProperties().setProperty("title", ""); this.attr.getProperties().setProperty("xtitle", ""); this.attr.getProperties().setProperty("ytitle", ""); }
/** * Creates an error buffer with each element being 0.0 * * @return a double 2D array with a size of xAxis * yAxis with each element being 0.0 */ public double[][] getErrorBuffer() { double[][] buff = new double[xAxis.getNBins()][yAxis.getNBins()]; for (int xloop = 0; xloop < xAxis.getNBins(); xloop++) { for (int yloop = 0; yloop < yAxis.getNBins(); yloop++) { buff[xloop][yloop] = 0.0; } } return buff; }
/** * Generates a 2D array with the content in the histogram * * @return a 2D array with each bin in its array index */ public double[][] getContentBuffer() { double[][] buff = new double[xAxis.getNBins()][yAxis.getNBins()]; for (int xloop = 0; xloop < xAxis.getNBins(); xloop++) { for (int yloop = 0; yloop < yAxis.getNBins(); yloop++) { buff[xloop][yloop] = this.getBinContent(xloop, yloop); } } return buff; }
/** * Creates a projection of the 2D histogram onto the Y Axis, adding up all the x bins for each y * bin * * @return a H1D object that is a projection of the Histogram2D object onto the y-axis */ public H1D projectionY() { String name = "Y Projection"; double yMin = yAxis.min(); double yMax = yAxis.max(); int yNum = yAxis.getNBins(); H1D projY = new H1D(name, yNum, yMin, yMax); double height = 0.0; for (int y = 0; y < yAxis.getNBins(); y++) { height = 0.0; for (int x = 0; x < xAxis.getNBins(); x++) { height += this.getBinContent(x, y); } projY.setBinContent(y, height); } return projY; }
/** * Creates a projection of the 2D histogram onto the X Axis, adding up all the y bins for each x * bin * * @return a H1D object that is a projection of the Histogram2D object onto the x-axis */ public H1D projectionX() { String name = "X Projection"; double xMin = xAxis.min(); double xMax = xAxis.max(); int xNum = xAxis.getNBins(); H1D projX = new H1D(name, xNum, xMin, xMax); double height = 0.0; for (int x = 0; x < xAxis.getNBins(); x++) { height = 0.0; for (int y = 0; y < yAxis.getNBins(); y++) { height += this.getBinContent(x, y); } projX.setBinContent(x, height); } return projX; }
/** * Creates a 1-D Histogram slice of the specified y Bin * * @param xBin the bin on the y axis to create a slice of * @return a slice of the x bins on the specified y bin as a 1-D Histogram */ public H1D sliceX(int xBin) { String name = "Slice of " + xBin + " X Bin"; double xMin = yAxis.min(); double xMax = yAxis.max(); int xNum = yAxis.getNBins(); H1D sliceX = new H1D(name, name, xNum, xMin, xMax); for (int x = 0; x < xNum; x++) { sliceX.setBinContent(x, this.getBinContent(xBin, x)); } return sliceX; }
/** * Creates a 1-D Histogram slice of the specified x Bin * * @param yBin the bin on the x axis to create a slice of * @return a slice of the y bins on the specified x bin as a 1-D Histogram */ public H1D sliceY(int yBin) { String name = "Slice of " + yBin + " Y Bin"; double xMin = xAxis.min(); double xMax = xAxis.max(); int xNum = xAxis.getNBins(); H1D sliceY = new H1D(name, name, xNum, xMin, xMax); for (int y = 0; y < xNum; y++) { sliceY.setBinContent(y, this.getBinContent(y, yBin)); } return sliceY; }
/** * Checks if that bin is valid (exists) * * @param bx The x coordinate of the bin * @param by The y coordinate of the bin * @return The truth value of the validity of that bin */ private boolean isValidBins(int bx, int by) { if ((bx >= 0) && (bx <= xAxis.getNBins()) && (by >= 0) && (by <= yAxis.getNBins())) { return true; } return false; }