package jasext.jhplotserver;
import java.awt.Color;
import hep.aida.IFunction;
import jas2.hist.Basic1DFunction;
import jas2.hist.Fitter;
import jas2.hist.FunctionValueUndefined;
import jas2.hist.Handle;
import jas2.hist.HasStyle;
import jas2.hist.InvalidFunctionParameter;
import jas2.hist.JASHist;
import jas2.hist.JASHist1DFunctionData;
import jas2.hist.JASHist1DFunctionStyle;
import jas2.hist.JASHistStyle;
/**
* Create a function to be showm in the menu.
* Note that a similar function we use in a templet, but h must be static in this case!
*
* @author sergei
*
*/
public class RefF1D extends FunctionData1DWithType
{
final private static String type="function1d";
// note: for templet it must be a static! This is only for list of functions
private IFunction h;
private double xmin, xmax, ymin, ymax;
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Initialze the function
* @param h
*/
public RefF1D(final IFunction h){
super();
this.h=h;
}
/**
* Initialze the function
* @param h
*/
public RefF1D(){
super();
}
public RefF1D(double xmin, double xmax, double ymin, double ymax)
{
this.xmin=xmin;
this.ymin=ymin;
this.xmax=xmax;
this.ymax=ymax;
}
public void setH(IFunction h) {
this.h = h;
}
@Override
public double valueAt(double x){
//System.out.println("Call valueAtX at:");
//System.out.println(x);
//System.out.println("Dimension:");
//System.out.println(h.dimension());
double[] xx = new double[h.dimension()];
xx[0] = x;
return h.value(xx);
}
@Override
public double[] getParameterValues() {
return h.parameters();
}
@Override
public String[] getParameterNames() {
return h.parameterNames();
}
@Override
public void setParameter(int index, double value) {
String s=h.variableName(index);
h.setParameter(s, value);
}
@Override
public String getTitle() {
return h.title();
}
@Override
String getType() {
return type;
}
public void setFit(Fitter fit, double[] value)
{
if (value.length != h.numberOfParameters())
throw new IllegalArgumentException("Argument to setParameters is of wrong length");
// max = value[0];
// mean = value[1];
// sigma = value[2];
h.setParameters(value);
setFit(fit);
setChanged();
}
@Override
public double valueAt(double x, double[] param){
double[] xx = new double[h.dimension()];
h.setParameters(param);
xx[0] = x;
return h.value(xx);
}
/*
public JASHist1DFunctionStyle getStyle() {
JASHist1DFunctionStyle style = new JASHist1DFunctionStyle();
style.setLineWidth(2);
style.setLineColor(Color.red);
return style;
*/
}
Ads help maintain this website.