From 71928a8894e43ebb949e70df12baf4d9fce1972c Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Thu, 31 Dec 2015 16:09:05 +0300 Subject: [PATCH] Total plot refactoring --- .../cryotemp/PKT8MainViewController.java | 2 +- .../control/msp/fx/MspViewController.java | 2 +- .../java/inr/numass/readvac/VACFrame.java | 2 +- .../plotfit/PlotFitResultAction.java | 59 +++++----- .../main/java/inr/numass/NumassPlugin.java | 2 +- .../inr/numass/actions/MergeDataAction.java | 2 +- .../numass/actions/ShowSpectrumAction.java | 3 +- .../main/java/inr/numass/data/RawNMPoint.java | 5 + .../inr/numass/models/LossCalculator.java | 7 -- .../inr/numass/workbench/PlotOutputTab.java | 20 ++-- .../java/inr/numass/models/PlotScatter.java | 4 +- .../models/TestNeLossParametrisation.java | 107 +++++++++--------- .../models/TransmissionInterpolatorTest.java | 51 +++++---- .../hep/dataforge/numass/prop/TestReader.java | 3 +- .../inr/numass/storage/NumassDataLoader.java | 3 +- numass-viewer/build.gradle | 2 +- .../numass/viewer/MainViewerController.java | 7 +- .../viewer/NumassLoaderViewComponent.java | 4 +- .../src/main/resources/fxml/MainView.fxml | 16 +-- 19 files changed, 152 insertions(+), 149 deletions(-) diff --git a/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8MainViewController.java b/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8MainViewController.java index 498ab1af..584542e9 100644 --- a/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8MainViewController.java +++ b/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8MainViewController.java @@ -166,7 +166,7 @@ public class PKT8MainViewController implements Initializable, DeviceListener, Me plotConfig = new MetaBuilder("plotFrame") .setValue("xAxis.timeAxis", true); } - plotFrame = new JFreeChartFrame("plot", plotConfig, plotArea); + plotFrame = new JFreeChartFrame("plot", plotConfig).display(plotArea); } public void setupDevice(Meta deviceMeta) throws ControlException { diff --git a/numass-control/msp/src/main/java/inr/numass/control/msp/fx/MspViewController.java b/numass-control/msp/src/main/java/inr/numass/control/msp/fx/MspViewController.java index b23b2ee6..9f21fa15 100644 --- a/numass-control/msp/src/main/java/inr/numass/control/msp/fx/MspViewController.java +++ b/numass-control/msp/src/main/java/inr/numass/control/msp/fx/MspViewController.java @@ -191,7 +191,7 @@ public class MspViewController implements Initializable, MspListener { .setValue("axisUnits", "mbar") ) .setValue("xAxis.timeAxis", true); - this.plotFrame = new JFreeChartFrame(mspName, plotConfig, plotPane); + this.plotFrame = new JFreeChartFrame(mspName, plotConfig).display(plotPane); updatePlot(); // this.plot = DynamicPlot.attachToFX(plotPane, new AnnotationBuilder("plot-config").putValue("logY", true).build()); // plot.setAutoRange(30 * 60); diff --git a/numass-control/vac/src/main/java/inr/numass/readvac/VACFrame.java b/numass-control/vac/src/main/java/inr/numass/readvac/VACFrame.java index c068db2d..1bdda54b 100644 --- a/numass-control/vac/src/main/java/inr/numass/readvac/VACFrame.java +++ b/numass-control/vac/src/main/java/inr/numass/readvac/VACFrame.java @@ -433,7 +433,7 @@ public class VACFrame extends javax.swing.JFrame { .setValue("axisUnits", "mbar") ) .setValue("xAxis.timeAxis", true); - this.plotFrame = new JFreeChartFrame("pressures", plotConfig, chartPannel); + this.plotFrame = new JFreeChartFrame("pressures", plotConfig).display(chartPannel); XYPlot xyPlot = plotFrame.getChart().getXYPlot(); LogarithmicAxis logAxis = new LogarithmicAxis("Pressure (mbar)"); diff --git a/numass-main/src/main/java/hep/dataforge/plotfit/PlotFitResultAction.java b/numass-main/src/main/java/hep/dataforge/plotfit/PlotFitResultAction.java index fe16c3dc..8c424b8f 100644 --- a/numass-main/src/main/java/hep/dataforge/plotfit/PlotFitResultAction.java +++ b/numass-main/src/main/java/hep/dataforge/plotfit/PlotFitResultAction.java @@ -28,12 +28,10 @@ import hep.dataforge.description.ValueDef; import hep.dataforge.description.TypedActionDef; import hep.dataforge.exceptions.ContentException; import hep.dataforge.io.log.Logable; -import hep.dataforge.plots.PlotFrame; import hep.dataforge.plots.PlotsPlugin; import hep.dataforge.plots.XYPlotFrame; import hep.dataforge.plots.data.PlottableData; import hep.dataforge.plots.data.PlottableFunction; -import hep.dataforge.plots.jfreechart.JFreeChartFrame; import java.util.ArrayList; import java.util.List; import org.apache.commons.math3.analysis.UnivariateFunction; @@ -52,58 +50,59 @@ public class PlotFitResultAction extends OneToOneAction { } @Override - protected FitState execute(Logable log, Meta metaData, FitState input){ + protected FitState execute(Logable log, Meta metaData, FitState input) { DataSet data = input.getDataSet(); - if(!(input.getModel() instanceof XYModel)){ + if (!(input.getModel() instanceof XYModel)) { log.logError("The fit model should be instance of XYModel for this action. Action failed!"); return input; } - XYModel model = (XYModel)input.getModel(); - + XYModel model = (XYModel) input.getModel(); + XYDataAdapter adapter; - if (metaData.hasNode("adapter")){ + if (metaData.hasNode("adapter")) { adapter = new XYDataAdapter(metaData.getNode("adapter")); - } else if(input.getModel() instanceof XYModel){ + } else if (input.getModel() instanceof XYModel) { adapter = model.getAdapter(); - } else throw new ContentException("No adapter defined for data interpretation"); - + } else { + throw new ContentException("No adapter defined for data interpretation"); + } + UnivariateFunction function = (double x) -> model.getSpectrum().value(x, input.getParameters()); - - XYPlotFrame frame = (XYPlotFrame) PlotsPlugin.buildFrom(getContext()).buildPlotFrame(getName(), input.getName(), metaData); - //JFreeChartFrame.drawFrame(reader.getString("plotTitle", "Fit result plot for "+input.getName()), null); - + + XYPlotFrame frame = (XYPlotFrame) PlotsPlugin + .buildFrom(getContext()).buildPlotFrame(getName(), input.getName(), + metaData.getNode("plot", null)); + //JFreeChartFrame.drawFrame(reader.getString("plotTitle", "Fit result plot for "+input.getName()), null); + double[] x = new double[data.size()]; - + // double[] y = new double[data.size()]; - - double xMin = Double.POSITIVE_INFINITY; - - double xMax = Double.NEGATIVE_INFINITY; - + + double xMax = Double.NEGATIVE_INFINITY; + List points = new ArrayList<>(); - + for (int i = 0; i < data.size(); i++) { x[i] = adapter.getX(data.get(i)).doubleValue(); // y[i] = adapter.getY(data.get(i)); points.add(adapter.mapToDefault(data.get(i))); - if(x[i]xMax){ + + if (x[i] > xMax) { xMax = x[i]; - } + } } - + frame.add(new PlottableFunction("fit", null, function, points, "x")); - + frame.add(new PlottableData("data", null, points)); - - + return input; } - + } diff --git a/numass-main/src/main/java/inr/numass/NumassPlugin.java b/numass-main/src/main/java/inr/numass/NumassPlugin.java index 58ef70ef..40191613 100644 --- a/numass-main/src/main/java/inr/numass/NumassPlugin.java +++ b/numass-main/src/main/java/inr/numass/NumassPlugin.java @@ -66,7 +66,7 @@ public class NumassPlugin extends BasicPlugin { @Override public void apply(Context context) { - FitManager fm = context.provide("hep.dataforge:fitting", FitPlugin.class).getFitManager(); + FitManager fm = context.provide("fitting", FitPlugin.class).getFitManager(); ModelManager mm = fm.getModelManager(); loadModels(mm); diff --git a/numass-main/src/main/java/inr/numass/actions/MergeDataAction.java b/numass-main/src/main/java/inr/numass/actions/MergeDataAction.java index f9c3de18..1984ce34 100644 --- a/numass-main/src/main/java/inr/numass/actions/MergeDataAction.java +++ b/numass-main/src/main/java/inr/numass/actions/MergeDataAction.java @@ -53,7 +53,7 @@ public class MergeDataAction extends ManyToOneAction { @Override protected List> buildGroups(Meta reader, List input) { List> groups; - if (reader.hasNode("grouping")) { + if (reader.hasValue("grouping.byValue")) { groups = super.buildGroups(reader, input); } else { groups = GroupBuilder.byValue(MERGE_NAME, reader.getString(MERGE_NAME, "merge")).group(input); diff --git a/numass-main/src/main/java/inr/numass/actions/ShowSpectrumAction.java b/numass-main/src/main/java/inr/numass/actions/ShowSpectrumAction.java index 1397eaf2..a16660a4 100644 --- a/numass-main/src/main/java/inr/numass/actions/ShowSpectrumAction.java +++ b/numass-main/src/main/java/inr/numass/actions/ShowSpectrumAction.java @@ -19,6 +19,7 @@ import hep.dataforge.actions.OneToOneAction; import hep.dataforge.context.Context; import hep.dataforge.description.TypedActionDef; import hep.dataforge.exceptions.ContentException; +import hep.dataforge.plots.fx.FXPlotUtils; import hep.dataforge.io.ColumnedDataWriter; import hep.dataforge.io.log.Logable; import hep.dataforge.meta.Meta; @@ -154,7 +155,7 @@ public class ShowSpectrumAction extends OneToOneAction { axisName += " per " + binning + " chanels"; } - JFreeChartFrame frame = JFreeChartFrame.drawFrame(head, null); + JFreeChartFrame frame = FXPlotUtils.displayJFreeChart(head, null); frame.getYAxisConfig().putValue("title", axisName); diff --git a/numass-main/src/main/java/inr/numass/data/RawNMPoint.java b/numass-main/src/main/java/inr/numass/data/RawNMPoint.java index 2096b214..5fb619a1 100644 --- a/numass-main/src/main/java/inr/numass/data/RawNMPoint.java +++ b/numass-main/src/main/java/inr/numass/data/RawNMPoint.java @@ -26,7 +26,9 @@ import java.util.List; */ public class RawNMPoint implements Cloneable { + public static final int MAX_EVENTS_PER_POINT = 260000; public static int MAX_CHANEL = 4095; + private Instant startTime; private final List events; private double length; @@ -103,6 +105,9 @@ public class RawNMPoint implements Cloneable { if (Double.isNaN(length)) { throw new Error(); } + if(events.size()>MAX_EVENTS_PER_POINT){ + return events.get(events.size()-1).getTime()-events.get(0).getTime(); + } return length; } diff --git a/numass-main/src/main/java/inr/numass/models/LossCalculator.java b/numass-main/src/main/java/inr/numass/models/LossCalculator.java index fdabb305..c41c1fc5 100644 --- a/numass-main/src/main/java/inr/numass/models/LossCalculator.java +++ b/numass-main/src/main/java/inr/numass/models/LossCalculator.java @@ -15,19 +15,12 @@ */ package inr.numass.models; -import hep.dataforge.context.Context; -import hep.dataforge.context.GlobalContext; import hep.dataforge.functions.FunctionCaching; -import hep.dataforge.io.log.Logable; import hep.dataforge.maths.NamedDoubleSet; import hep.dataforge.maths.integration.GaussRuleIntegrator; import hep.dataforge.maths.integration.UnivariateIntegrator; -import hep.dataforge.meta.MetaBuilder; -import hep.dataforge.plots.PlotFrame; -import hep.dataforge.plots.PlotsPlugin; import hep.dataforge.plots.XYPlotFrame; import hep.dataforge.plots.data.PlottableFunction; -import hep.dataforge.plots.jfreechart.JFreeChartFrame; import static java.lang.Math.exp; import java.util.ArrayList; import java.util.HashMap; diff --git a/numass-main/src/main/java/inr/numass/workbench/PlotOutputTab.java b/numass-main/src/main/java/inr/numass/workbench/PlotOutputTab.java index 71c9d6e3..fb17236d 100644 --- a/numass-main/src/main/java/inr/numass/workbench/PlotOutputTab.java +++ b/numass-main/src/main/java/inr/numass/workbench/PlotOutputTab.java @@ -5,26 +5,30 @@ */ package inr.numass.workbench; +import hep.dataforge.plots.fx.PlotContainer; import hep.dataforge.meta.Meta; import hep.dataforge.plots.jfreechart.JFreeChartFrame; -import javafx.scene.layout.AnchorPane; public class PlotOutputTab extends OutputTab { - private JFreeChartFrame frame; + private final JFreeChartFrame frame; public PlotOutputTab(String name, Meta meta) { super(name); - AnchorPane pane = new AnchorPane(); - frame = new JFreeChartFrame(name, meta, pane); - setContent(pane); + PlotContainer container = new PlotContainer(); + frame = new JFreeChartFrame(name, meta); + container.setPlot(frame); +// AnchorPane pane = new AnchorPane(); +// frame = new JFreeChartFrame(name, meta).display(pane); + setContent(container); } public PlotOutputTab(String name, String title, Meta meta) { super(name, title); - AnchorPane pane = new AnchorPane(); - frame = new JFreeChartFrame(name, meta, pane); - setContent(pane); + PlotContainer container = new PlotContainer(); + frame = new JFreeChartFrame(name, meta); + container.setPlot(frame); + setContent(container); } @Override diff --git a/numass-main/src/test/java/inr/numass/models/PlotScatter.java b/numass-main/src/test/java/inr/numass/models/PlotScatter.java index da7c2652..3091d177 100644 --- a/numass-main/src/test/java/inr/numass/models/PlotScatter.java +++ b/numass-main/src/test/java/inr/numass/models/PlotScatter.java @@ -16,7 +16,7 @@ package inr.numass.models; import hep.dataforge.datafitter.ParamSet; -import hep.dataforge.plots.jfreechart.JFreeChartFrame; +import hep.dataforge.plots.fx.FXPlotUtils; /** * @@ -36,6 +36,6 @@ public class PlotScatter { + "'ionW' = 11.33 ± 0.43\n" + "'exIonRatio' = 4.83 ± 0.36" ); - LossCalculator.plotScatter(JFreeChartFrame.drawFrame("Loss function", null),pars); + LossCalculator.plotScatter(FXPlotUtils.displayJFreeChart("Loss function", null),pars); } } diff --git a/numass-main/src/test/java/inr/numass/models/TestNeLossParametrisation.java b/numass-main/src/test/java/inr/numass/models/TestNeLossParametrisation.java index 0f835765..635eb766 100644 --- a/numass-main/src/test/java/inr/numass/models/TestNeLossParametrisation.java +++ b/numass-main/src/test/java/inr/numass/models/TestNeLossParametrisation.java @@ -13,56 +13,57 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package inr.numass.models; - -import hep.dataforge.maths.integration.GaussRuleIntegrator; -import hep.dataforge.plots.PlotFrame; -import hep.dataforge.plots.data.PlottableFunction; -import hep.dataforge.plots.jfreechart.JFreeChartFrame; -import org.apache.commons.math3.analysis.UnivariateFunction; - -/** - * - * @author Alexander Nozik - */ -public class TestNeLossParametrisation { - - /** - * @param args the command line arguments - */ - public static void main(String[] args) { - PlotFrame frame = JFreeChartFrame.drawFrame("Loss parametrisation test", null); - UnivariateFunction oldFunction = LossCalculator.getSingleScatterFunction(); - UnivariateFunction newFunction = getSingleScatterFunction(12.86, 16.78, 1.65, 12.38, 4.79); - - Double norm = new GaussRuleIntegrator(200).integrate(newFunction, 0d, 100d); - - System.out.println(norm); - - frame.add(new PlottableFunction("old", null, oldFunction, 0, 30, 300)); - frame.add(new PlottableFunction("new", null, newFunction, 0, 30, 300)); - } - - public static UnivariateFunction getSingleScatterFunction( - final double exPos, - final double ionPos, - final double exW, - final double ionW, - final double exIonRatio) { - - return (double eps) -> { - if (eps <= 0) { - return 0; - } - double z = eps - exPos; - // Используется полная ширина, а не полуширина. - double res = exIonRatio * Math.exp(-2 * z * z / exW / exW) * Math.sqrt(2 / Math.PI) / exW; - - if (eps >= ionPos) { - z = 4 * (eps - ionPos) * (eps - ionPos); - res += 4d / (1 + z / ionW / ionW) / Math.PI / ionW; - } - return res / (1 + exIonRatio); - }; - } -} +package inr.numass.models; + +import hep.dataforge.plots.fx.FXPlotUtils; +import hep.dataforge.maths.integration.GaussRuleIntegrator; +import hep.dataforge.plots.PlotFrame; +import hep.dataforge.plots.data.PlottableFunction; +import org.apache.commons.math3.analysis.UnivariateFunction; + +/** + * + * @author Alexander Nozik + */ +public class TestNeLossParametrisation { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + PlotFrame frame = FXPlotUtils.displayJFreeChart("Loss parametrisation test", null); + //JFreeChartFrame.drawFrame("Loss parametrisation test", null); + UnivariateFunction oldFunction = LossCalculator.getSingleScatterFunction(); + UnivariateFunction newFunction = getSingleScatterFunction(12.86, 16.78, 1.65, 12.38, 4.79); + + Double norm = new GaussRuleIntegrator(200).integrate(newFunction, 0d, 100d); + + System.out.println(norm); + + frame.add(new PlottableFunction("old", null, oldFunction, 0, 30, 300)); + frame.add(new PlottableFunction("new", null, newFunction, 0, 30, 300)); + } + + public static UnivariateFunction getSingleScatterFunction( + final double exPos, + final double ionPos, + final double exW, + final double ionW, + final double exIonRatio) { + + return (double eps) -> { + if (eps <= 0) { + return 0; + } + double z = eps - exPos; + // Используется полная ширина, а не полуширина. + double res = exIonRatio * Math.exp(-2 * z * z / exW / exW) * Math.sqrt(2 / Math.PI) / exW; + + if (eps >= ionPos) { + z = 4 * (eps - ionPos) * (eps - ionPos); + res += 4d / (1 + z / ionW / ionW) / Math.PI / ionW; + } + return res / (1 + exIonRatio); + }; + } +} diff --git a/numass-main/src/test/java/inr/numass/models/TransmissionInterpolatorTest.java b/numass-main/src/test/java/inr/numass/models/TransmissionInterpolatorTest.java index baa05ecc..93bdd9a1 100644 --- a/numass-main/src/test/java/inr/numass/models/TransmissionInterpolatorTest.java +++ b/numass-main/src/test/java/inr/numass/models/TransmissionInterpolatorTest.java @@ -13,28 +13,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package inr.numass.models; - -import hep.dataforge.context.GlobalContext; -import hep.dataforge.plots.data.PlottableData; -import hep.dataforge.plots.data.PlottableFunction; -import hep.dataforge.plots.jfreechart.JFreeChartFrame; - -/** - * - * @author darksnake - */ -public class TransmissionInterpolatorTest { - - public static void main(String[] args) { - JFreeChartFrame frame = JFreeChartFrame.drawFrame("TransmissionInterpolatorTest", null); - TransmissionInterpolator interpolator = TransmissionInterpolator.fromFile(GlobalContext.instance(), - "d:\\sterile-new\\loss2014-11\\.dataforge\\merge\\empty_sum.out", "Uset", "CR", 15, 0.8, 19002d); - frame.add(new PlottableData("data", interpolator.getX(), interpolator.getY())); - frame.add(new PlottableFunction("interpolated", null, interpolator, interpolator.getXmin(), interpolator.getXmax(), 2000)); - -// PrintFunction.printFuntionSimple(new PrintWriter(System.out), interpolator, interpolator.getXmin(), interpolator.getXmax(), 500); - - } - -} +package inr.numass.models; + +import hep.dataforge.context.GlobalContext; +import hep.dataforge.plots.fx.FXPlotUtils; +import hep.dataforge.plots.data.PlottableData; +import hep.dataforge.plots.data.PlottableFunction; +import hep.dataforge.plots.jfreechart.JFreeChartFrame; + +/** + * + * @author darksnake + */ +public class TransmissionInterpolatorTest { + + public static void main(String[] args) { + JFreeChartFrame frame = FXPlotUtils.displayJFreeChart("TransmissionInterpolatorTest", null); +//JFreeChartFrame.drawFrame("TransmissionInterpolatorTest", null); + TransmissionInterpolator interpolator = TransmissionInterpolator.fromFile(GlobalContext.instance(), + "d:\\sterile-new\\loss2014-11\\.dataforge\\merge\\empty_sum.out", "Uset", "CR", 15, 0.8, 19002d); + frame.add(new PlottableData("data", interpolator.getX(), interpolator.getY())); + frame.add(new PlottableFunction("interpolated", null, interpolator, interpolator.getXmin(), interpolator.getXmax(), 2000)); + +// PrintFunction.printFuntionSimple(new PrintWriter(System.out), interpolator, interpolator.getXmin(), interpolator.getXmax(), 500); + } + +} diff --git a/numass-prop/src/test/java/hep/dataforge/numass/prop/TestReader.java b/numass-prop/src/test/java/hep/dataforge/numass/prop/TestReader.java index 09460863..0e7be321 100644 --- a/numass-prop/src/test/java/hep/dataforge/numass/prop/TestReader.java +++ b/numass-prop/src/test/java/hep/dataforge/numass/prop/TestReader.java @@ -19,6 +19,7 @@ import hep.dataforge.meta.Meta; import hep.dataforge.meta.MetaBuilder; import hep.dataforge.context.GlobalContext; import hep.dataforge.data.FileData; +import hep.dataforge.plots.fx.FXPlotUtils; import inr.numass.prop.ar.JNAEpisode; import inr.numass.prop.ar.JNASpectrum; import inr.numass.prop.ar.ReadJNADataAction; @@ -57,7 +58,7 @@ public class TestReader { System.out.printf("%g\t%d%n", entry.getKey(), entry.getValue()); } - PlotFrame frame = JFreeChartFrame.drawFrame("JNA_Test", null); + PlotFrame frame = FXPlotUtils.displayJFreeChart("JNA test", null); frame.add(new PlottableData(sp.asDataSet(), "chanel", "count")); diff --git a/numass-storage/src/main/java/inr/numass/storage/NumassDataLoader.java b/numass-storage/src/main/java/inr/numass/storage/NumassDataLoader.java index a901aae7..c236fc73 100644 --- a/numass-storage/src/main/java/inr/numass/storage/NumassDataLoader.java +++ b/numass-storage/src/main/java/inr/numass/storage/NumassDataLoader.java @@ -162,12 +162,13 @@ public class NumassDataLoader extends AbstractLoader implements BinaryLoader - - - - - - - -