New plot serialization. Minor dependency optimization.

This commit is contained in:
Alexander Nozik 2016-05-28 15:50:06 +03:00
parent a38a770f5e
commit e2dace1504
5 changed files with 10 additions and 9 deletions

View File

@ -32,6 +32,7 @@ import hep.dataforge.plots.data.PlottableData;
import hep.dataforge.plots.data.PlottableFunction;
import hep.dataforge.tables.PointSource;
import hep.dataforge.tables.XYAdapter;
import java.util.function.Function;
import org.apache.commons.math3.analysis.UnivariateFunction;
/**
@ -62,7 +63,7 @@ public class PlotFitResultAction extends OneToOneAction<FitState, FitState> {
throw new ContentException("No adapter defined for data interpretation");
}
UnivariateFunction function = (double x) -> model.getSpectrum().value(x, input.getParameters());
Function<Double, Double> function = (x) -> model.getSpectrum().value(x, input.getParameters());
XYPlotFrame frame = (XYPlotFrame) PlotsPlugin
.buildFrom(context).buildPlotFrame(getName(), name,

View File

@ -90,7 +90,7 @@ public class ShowLossSpectrumAction extends OneToOneAction<FitState, FitState> {
case "scatter-empiric-experimental":
scatterFunction = new ExperimentalVariableLossSpectrum.Loss(0.3).total(pars);
frame.add(new PlottableFunction("Cross-section", scatterFunction, 0, 100, 1000));
frame.add(new PlottableFunction("Cross-section", (x) -> scatterFunction.value(x), 0, 100, 1000));
break;
default:
throw new RuntimeException("Can work only with variable loss spectra");

View File

@ -168,12 +168,12 @@ public class LossCalculator {
final LossCalculator loss = LossCalculator.instance;
final List<Double> probs = loss.getGunLossProbabilities(set.getValue("X"));
UnivariateFunction single = (double e) -> probs.get(1) * scatterFunction.value(e);
frame.add(new PlottableFunction("Single scattering", single, 0, 100, 1000));
frame.add(new PlottableFunction("Single scattering", x->single.value(x), 0, 100, 1000));
for (int i = 2; i < probs.size(); i++) {
final int j = i;
UnivariateFunction scatter = (double e) -> probs.get(j) * loss.getLossValue(j, e, 0d);
frame.add(new PlottableFunction(j + " scattering", scatter, 0, 100, 1000));
frame.add(new PlottableFunction(j + " scattering", x->scatter.value(x), 0, 100, 1000));
}
UnivariateFunction total = (eps) -> {
@ -187,11 +187,11 @@ public class LossCalculator {
return sum;
};
frame.add(new PlottableFunction("Total loss", total, 0, 100, 1000));
frame.add(new PlottableFunction("Total loss", x->total.value(x), 0, 100, 1000));
} else {
frame.add(new PlottableFunction("Differential crosssection", scatterFunction, 0, 100, 2000));
frame.add(new PlottableFunction("Differential crosssection", x->scatterFunction.value(x), 0, 100, 2000));
}
}

View File

@ -40,8 +40,8 @@ public class TestNeLossParametrisation {
System.out.println(norm);
frame.add(new PlottableFunction("old", oldFunction, 0, 30, 300));
frame.add(new PlottableFunction("new", newFunction, 0, 30, 300));
frame.add(new PlottableFunction("old", x->oldFunction.value(x), 0, 30, 300));
frame.add(new PlottableFunction("new", x->newFunction.value(x), 0, 30, 300));
}
public static UnivariateFunction getSingleScatterFunction(

View File

@ -33,7 +33,7 @@ public class TransmissionInterpolatorTest {
TransmissionInterpolator interpolator = TransmissionInterpolator.fromFile(GlobalContext.instance(),
"d:\\sterile-new\\loss2014-11\\.dataforge\\merge\\empty_sum.out", "Uset", "CR", 15, 0.8, 19002d);
frame.add(PlottableData.plot("data", interpolator.getX(), interpolator.getY()));
frame.add(new PlottableFunction("interpolated", interpolator, interpolator.getXmin(), interpolator.getXmax(), 2000));
frame.add(new PlottableFunction("interpolated", x->interpolator.value(x), interpolator.getXmin(), interpolator.getXmax(), 2000));
// PrintFunction.printFuntionSimple(new PrintWriter(System.out), interpolator, interpolator.getXmin(), interpolator.getXmax(), 500);
}