Java source code of 'jhplot.HProf2D'

/**
*    Copyright (C)  DataMelt project. The jHPLot package by S.Chekanov and Work.ORG
*    All rights reserved.
*
*    This program is free software; you can redistribute it and/or modify it under the terms
*    of the GNU General Public License as published by the Free Software Foundation; either
*    version 3 of the License, or any later version.
*
*    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
*    without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*    See the GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License along with this program;
*    if not, see .
*
*    Additional permission under GNU GPL version 3 section 7:
*    If you have received this program as a library with written permission from the DataMelt team,
*    you can link or combine this library with your non-GPL project to convey the resulting work.
*    In this case, this library should be considered as released under the terms of
*    GNU Lesser public license (see ),
*    provided you include this license notice and a URL through which recipients can access the
*    Corresponding Source.
**/
package jhplot;

import hep.aida.*;
import hep.aida.ref.histogram.*;
import java.io.*;

import jhplot.gui.HelpBrowser;

/**
 * Profile  histogram in 2D.
 * The profile histogram is used to show the mean value in each bin 
 * as a function of a second variable. Use getH2D() method
 * for plotting. Points can have errors shown as error on mean or RMS.
 * 
 * Based on JAIDA class Profile2D.
 * 
 * @author S.Chekanov
 * 
 */

public class HProf2D implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Profile2D h1;

	private double minX;

	private double maxX;

	private double minY;

	private double maxY;

	private int binsX;

	private int binsY;
	
	private IAxis xAx;
	
	private IAxis yAy; 

	private int region = 0;

	private String title;

	/**
	 * Create 2D histogram
	 * 
	 * @param title
	 *            Title
	 * @param binsX
	 *            Number of bins in X
	 * @param minX
	 *            Min value in X
	 * @param maxX
	 *            Max value in X
	 * @param binsY
	 *            Number of bins in Y
	 * @param minY
	 *            Min value in Y
	 * @param maxY
	 *            Max value in Y
	 */
	public HProf2D(String title, int binsX, double minX, double maxX, int binsY,
			double minY, double maxY) {

		this.title = title;
		this.binsX = binsX;
		this.minX = minX;
		this.maxX = maxX;
		this.binsY = binsY;
		this.minY = minY;
		this.maxY = maxY;

		/*
		 * // cannot treat different binnings yet int Ibin = this.binsX; if
		 * (this.binsY > this.binsX) Ibin = this.binsY; this.binsX = Ibin;
		 * this.binsY = Ibin;
		 */
		xAx = new FixedAxis(this.binsX, this.minX, this.maxX);
	    yAy = new FixedAxis(this.binsY, this.minY, this.maxY);
		h1 = new Profile2D(this.title, this.title, xAx, yAy);

	}

	
	
	

	/**
	 * Create 2D profile histogram with variable bin size.
	 * 
	 * @param title
	 *            Title of histogram.
	 * @param edgesX
	 *            edges for X
	 * @param edgesY
	 *            edges for Y          
	 */
	public HProf2D(String title, double[] edgesX, double[] edgesY ) {

		
		
	    this.title = title;
		
	    this.binsX = edgesX.length - 1;
		this.minX = edgesX[0];
		this.maxX = edgesX[edgesX.length-1];
	
		this.binsY = edgesY.length - 1;
		this.minY = edgesY[0];
		this.maxY = edgesX[edgesY.length-1];
	
		xAx=new VariableAxis(edgesX);
		yAy=new VariableAxis(edgesY);
		
		h1 = new Profile2D(this.title, this.title, xAx, yAy);
	}
	
	

	
	
	
	
	/**
	 * Create a H2D histogram from JAIDA histogram
	 * 
	 * @param h1
	 *            Histogram2D histogram
	 */
	public HProf2D(Profile2D h1) {
		this.h1 = h1;
		setTitle(h1.title());
		xAx = h1.xAxis();
		yAy = h1.yAxis();
		this.minX = xAx.lowerEdge();
		this.maxX = xAx.upperEdge();
		this.minY = yAy.lowerEdge();
		this.maxY = yAy.upperEdge();
		this.binsX = xAx.bins();
		this.binsY = yAy.bins();
	}

	/**
	 * Set title
	 * @param title title
	 */
	public void setTitle(String title) {
		
		this.title = title;
		
	}
	/**
	 * Get the JAIDA Profile2D
	 * 
	 * @return Profile2D
	 */
	public Profile2D get() {

		return h1;

	}

	
	
	
	/**
	 * Make H2D copy of the current histogram.
	 * Default graphical attributes are assumed.
	 * Errors for points show errors on mean.
	 * 
	 * @param newtitle
	 *            New title
	 * @return  H2D histogram
	 */
	public H2D  getH2D(String newtitle) {
		return getH2D(newtitle,"mean"); 
	}
	
	
	
	/**
	 * Make H2D copy of the current histogram.
	 * Default graphical attributes are assumed.
	 * 
	 * @param newtitle
	 *            New title
	 * @param option
	 *              id option is "s", spread (RMS) is used as error
	 * @return  H2D histogram
	 */
	public H2D  getH2D(String newtitle, String option) {

		
	        int xbins = xAx.bins()+2;
	        int ybins = yAy.bins()+2;
	        double[][] newHeights = new double[xbins][ybins];
	        double[][] newErrors  = new double[xbins][ybins];
	        double[][] newMeanXs  = new double[xbins][ybins];
	        double[][] newRmsXs   = new double[xbins][ybins];
	        double[][] newMeanYs  = new double[xbins][ybins];
	        double[][] newRmsYs   = new double[xbins][ybins];   
	        int[][] newEntries = new    int[xbins][ybins];
	      
	        
	        
	        /*
	        for(int i=0; i= bins) throw new IllegalArgumentException("bin="+index);
        if (index >= 0) return index+1;
        if (index == IAxis.UNDERFLOW_BIN) return 0;
        if (index == IAxis.OVERFLOW_BIN) return bins-1;
        throw new IllegalArgumentException("bin="+index);
    }


	/**
	    * Show online documentation.
	    */
	      public void doc() {
	        	 
	    	  String a=this.getClass().getName();
	    	  a=a.replace(".", "/")+".html"; 
			  new HelpBrowser(  HelpBrowser.JHPLOT_HTTP+a);
	    	 
			  
			  
	      }

}