package org.jlab.groot.math;
import java.io.Serializable;
/**
* Defines the attributes for creating a basic axis template with
* a number of bins, a minimum value, and a maximum value
*
* @author Erin Kirby
* @version 062514
*/
public class Axis implements Serializable {
public double[] axisMargins;
private int numBins;
private String axisTitle = "x";
private double minVal;
private double maxVal;
private boolean isUniform = true;
/**
* Creates a default axis with 1 bin, a minimum value of 0, and maximum
* value of 1.0.
*/
public Axis() {
set(1, 0.0, 1.0);
}
/**
* Creates an axis using the desired limits for the bins
*
* @param limits an array of the upper and lower limits of each bin
*/
public Axis(double[] limits) {
this.set(limits);
this.isUniform = false;
}
/**
* Creates an axis using the provided number of bins, minimum value, and maximum value
*
* @param bins the number of bins to have on the axis
* @param min the minimum value for the axis
* @param max the maximum value for the axis
*/
public Axis(int bins, double min, double max) {
this.set(bins, min, max);
}
public void setTitle(String title) {this.axisTitle = title;}
public String getTitle(){ return this.axisTitle;}
/**
* Sets the specified limits to the axis
*
* @param limits the desired limits for the bins on the axis
*/
public final void set(double[] limits) {
axisMargins = new double[limits.length];
for (int i=0; i= 0 && bin= 0 && bin < numBins) {
return Math.abs(axisMargins[bin+1] - axisMargins[bin]);
}
return 0.0;
}
/**
* Finds the specified value and returns which bin it is in
* in array indexing format (i.e. if it is in the 1st bin, it would return 0, the 2nd bin would
* return 1, ... , the nth bin would return n-1).
*
* @param xVal the data value to find on the axis
* @return the bin where the specified value is in array indexing format
*/
public int getBin(double xVal) {
if(xVal= axisMargins[i] && xVal < axisMargins[i+1])) {
return i;
}
}
/*
if (xVal == axisMargins[axisMargins.length - 1]) {
return numBins;
}*/
return numBins;
}
/**
* Scales the range by a specified unit
*
* @param xUnit the unit to multiply the range of values by
* @return min value + ((max value - min value) * xUnit)
*/
public double convertFromUnit(double xUnit) {
double value = (maxVal - minVal) * xUnit;
return minVal + value;
}
}
Ads help maintain this website.