00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 package com.meapsoft;
00024
00025
00029 public class BasicHist
00030 {
00031 int [] bins;
00032 int numBins;
00033 int underflows;
00034 int overflows;
00035
00036 double lo;
00037 double hi;
00038 double range;
00039
00044 public BasicHist (int numBins, double lo, double hi) {
00045 this.numBins = numBins;
00046
00047 bins = new int[numBins];
00048
00049 this.lo = lo;
00050 this.hi = hi;
00051 range = hi - lo;
00052 }
00053
00059 public void add(double x) {
00060 if( x >= hi) overflows++;
00061 else if( x < lo) underflows++;
00062 else {
00063 double val = x - lo;
00064
00065
00066
00067 int bin = (int)(numBins * (val/range) );
00068
00069
00070 bins[bin]++;
00071 }
00072 }
00073
00075 public void clear() {
00076 for (int i=0; i < numBins; i++) {
00077 bins[i] = 0;
00078 overflows = 0;
00079 underflows= 0;
00080 }
00081 }
00082
00084 public int getValue(int bin) {
00085 if (bin < 0)
00086 return underflows;
00087 else if( bin >= numBins)
00088 return overflows;
00089 else
00090 return bins[bin];
00091 }
00092 }