From e1d0c507453527a7a8506b12d0fe7ac00b8fdff7 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 14 Aug 2016 16:24:12 +0300 Subject: [PATCH] Grind dsl refinement + task & workspace fixes --- .../plotfit/PlotFitResultAction.java | 11 ++--- .../numass/actions/AdjustErrorsAction.java | 4 +- .../inr/numass/actions/DebunchAction.java | 17 +++---- .../inr/numass/actions/FindBorderAction.java | 14 +++--- .../inr/numass/actions/MergeDataAction.java | 5 +- .../numass/actions/MonitorCorrectAction.java | 5 +- .../actions/PileupSimulationAction.java | 5 +- .../inr/numass/actions/PrepareDataAction.java | 4 +- .../numass/actions/ReadNumassDataAction.java | 9 ++-- .../actions/ShowEnergySpectrumAction.java | 18 ++----- .../actions/ShowLossSpectrumAction.java | 10 ++-- .../inr/numass/actions/SlicingAction.java | 12 ++--- .../actions/SubstractSpectrumAction.java | 7 ++- .../inr/numass/actions/SummaryAction.java | 16 +++--- .../src/main/java/inr/numass/models/FSS.java | 5 +- .../inr/numass/models/LossCalculator.java | 40 ++++++++------- .../java/inr/numass/tasks/GrindCaller.java | 2 +- .../tasks/NumassFitScanSummaryTask.java | 27 +++++++--- .../inr/numass/tasks/NumassFitScanTask.java | 41 +++++++++------- .../inr/numass/tasks/NumassPrepareTask.java | 8 +-- .../numass/tasks/NumassTableFilterTask.java | 49 +++++++++++++++++++ 21 files changed, 175 insertions(+), 134 deletions(-) create mode 100644 numass-main/src/main/java/inr/numass/tasks/NumassTableFilterTask.java 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 ec0a519b..5c51e6ff 100644 --- a/numass-main/src/main/java/hep/dataforge/plotfit/PlotFitResultAction.java +++ b/numass-main/src/main/java/hep/dataforge/plotfit/PlotFitResultAction.java @@ -16,22 +16,21 @@ package hep.dataforge.plotfit; import hep.dataforge.actions.OneToOneAction; -import hep.dataforge.context.Context; -import hep.dataforge.stat.fit.FitState; -import hep.dataforge.stat.models.XYModel; import hep.dataforge.description.NodeDef; import hep.dataforge.description.TypedActionDef; import hep.dataforge.description.ValueDef; import hep.dataforge.exceptions.ContentException; -import hep.dataforge.io.reports.Reportable; import hep.dataforge.meta.Laminate; import hep.dataforge.meta.Meta; import hep.dataforge.plots.PlotsPlugin; import hep.dataforge.plots.XYPlotFrame; import hep.dataforge.plots.data.PlottableData; import hep.dataforge.plots.data.PlottableXYFunction; +import hep.dataforge.stat.fit.FitState; +import hep.dataforge.stat.models.XYModel; import hep.dataforge.tables.PointSource; import hep.dataforge.tables.XYAdapter; + import java.util.function.Function; import java.util.stream.StreamSupport; @@ -45,11 +44,11 @@ import java.util.stream.StreamSupport; public class PlotFitResultAction extends OneToOneAction { @Override - protected FitState execute(Reportable log, String name, Laminate metaData, FitState input) { + protected FitState execute(String name, Laminate metaData, FitState input) { PointSource data = input.getDataSet(); if (!(input.getModel() instanceof XYModel)) { - log.reportError("The fit model should be instance of XYModel for this action. Action failed!"); + getReport(name).reportError("The fit model should be instance of XYModel for this action. Action failed!"); return input; } XYModel model = (XYModel) input.getModel(); diff --git a/numass-main/src/main/java/inr/numass/actions/AdjustErrorsAction.java b/numass-main/src/main/java/inr/numass/actions/AdjustErrorsAction.java index fff75463..087c2a30 100644 --- a/numass-main/src/main/java/inr/numass/actions/AdjustErrorsAction.java +++ b/numass-main/src/main/java/inr/numass/actions/AdjustErrorsAction.java @@ -7,13 +7,13 @@ package inr.numass.actions; import hep.dataforge.actions.OneToOneAction; import hep.dataforge.description.TypedActionDef; -import hep.dataforge.io.reports.Reportable; import hep.dataforge.meta.Laminate; import hep.dataforge.meta.Meta; import hep.dataforge.tables.DataPoint; import hep.dataforge.tables.ListTable; import hep.dataforge.tables.MapPoint; import hep.dataforge.tables.Table; + import java.util.ArrayList; import java.util.List; @@ -26,7 +26,7 @@ import java.util.List; public class AdjustErrorsAction extends OneToOneAction { @Override - protected Table execute(Reportable log, String name, Laminate meta, Table input) { + protected Table execute(String name, Laminate meta, Table input) { List points = new ArrayList<>(); for (DataPoint dp : input) { points.add(evalPoint(meta, dp)); diff --git a/numass-main/src/main/java/inr/numass/actions/DebunchAction.java b/numass-main/src/main/java/inr/numass/actions/DebunchAction.java index ddf35baf..10094e01 100644 --- a/numass-main/src/main/java/inr/numass/actions/DebunchAction.java +++ b/numass-main/src/main/java/inr/numass/actions/DebunchAction.java @@ -19,16 +19,15 @@ import hep.dataforge.actions.OneToOneAction; import hep.dataforge.description.TypedActionDef; import hep.dataforge.description.ValueDef; import hep.dataforge.exceptions.ContentException; -import hep.dataforge.io.reports.Reportable; import hep.dataforge.meta.Laminate; -import inr.numass.storage.RawNMFile; -import inr.numass.storage.RawNMPoint; import inr.numass.debunch.DebunchReport; import inr.numass.debunch.FrameAnalizer; +import inr.numass.storage.RawNMFile; +import inr.numass.storage.RawNMPoint; + import java.io.PrintWriter; /** - * * @author Darksnake */ @TypedActionDef(name = "debunch", inputType = RawNMFile.class, outputType = RawNMFile.class) @@ -40,8 +39,8 @@ import java.io.PrintWriter; public class DebunchAction extends OneToOneAction { @Override - protected RawNMFile execute(Reportable log, String name, Laminate meta, RawNMFile source) throws ContentException { - log.report("File {} started", source.getName()); + protected RawNMFile execute(String name, Laminate meta, RawNMFile source) throws ContentException { + report(name, "File {} started", source.getName()); int upper = meta.getInt("upperchanel", RawNMPoint.MAX_CHANEL); int lower = meta.getInt("lowerchanel", 0); @@ -56,7 +55,7 @@ public class DebunchAction extends OneToOneAction { if (cr < maxCR) { DebunchReport report = new FrameAnalizer(rejectionprob, framelength, lower, upper).debunchPoint(point); - log.report("Debunching file '{}', point '{}': {} percent events {} percent time in bunches", + report(name, "Debunching file '{}', point '{}': {} percent events {} percent time in bunches", source.getName(), point.getUset(), report.eventsFiltred() * 100, report.timeFiltred() * 100); point = report.getPoint(); } @@ -64,9 +63,9 @@ public class DebunchAction extends OneToOneAction { }).forEach((point) -> { res.putPoint(point); }); - log.report("File {} completed", source.getName()); + report(name, "File {} completed", source.getName()); - log.getReport().print(new PrintWriter(buildActionOutput(name))); + getReport(name).print(new PrintWriter(buildActionOutput(name))); // res.configure(source.meta()); return res; diff --git a/numass-main/src/main/java/inr/numass/actions/FindBorderAction.java b/numass-main/src/main/java/inr/numass/actions/FindBorderAction.java index 4b7643da..f8daa632 100644 --- a/numass-main/src/main/java/inr/numass/actions/FindBorderAction.java +++ b/numass-main/src/main/java/inr/numass/actions/FindBorderAction.java @@ -16,11 +16,9 @@ package inr.numass.actions; import hep.dataforge.actions.OneToOneAction; -import hep.dataforge.context.Context; import hep.dataforge.description.TypedActionDef; import hep.dataforge.exceptions.ContentException; import hep.dataforge.io.ColumnedDataWriter; -import hep.dataforge.io.reports.Reportable; import hep.dataforge.meta.Laminate; import hep.dataforge.tables.ListTable; import hep.dataforge.tables.MapPoint; @@ -29,13 +27,13 @@ import hep.dataforge.values.Value; import inr.numass.storage.NMFile; import inr.numass.storage.NMPoint; import inr.numass.storage.NumassData; +import org.apache.commons.math3.analysis.UnivariateFunction; + import java.io.OutputStream; import java.util.HashMap; import java.util.Map; -import org.apache.commons.math3.analysis.UnivariateFunction; /** - * * @author Darksnake */ @TypedActionDef(name = "findBorder", inputType = NMFile.class, outputType = Table.class) @@ -47,8 +45,8 @@ public class FindBorderAction extends OneToOneAction { private UnivariateFunction normCorrection = e -> 1 + 13.265 * Math.exp(-e / 2343.4); @Override - protected Table execute(Reportable log, String name, Laminate meta, NumassData source) throws ContentException { - log.report("File {} started", source.getName()); + protected Table execute(String name, Laminate meta, NumassData source) throws ContentException { + report(name, "File {} started", source.getName()); int upperBorder = meta.getInt("upper", 4094); int lowerBorder = meta.getInt("lower", 0); @@ -58,7 +56,7 @@ public class FindBorderAction extends OneToOneAction { if (substractReference > 0) { referencePoint = source.getByUset(substractReference); if (referencePoint == null) { - log.report("Reference point {} not found", substractReference); + report(name, "Reference point {} not found", substractReference); } } @@ -71,7 +69,7 @@ public class FindBorderAction extends OneToOneAction { ColumnedDataWriter.writeDataSet(stream, bData, String.format("%s : lower = %d upper = %d", name, lowerBorder, upperBorder)); - log.report("File {} completed", source.getName()); + report(name, "File {} completed", source.getName()); return bData; } 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 18ca4e2e..2a5053c2 100644 --- a/numass-main/src/main/java/inr/numass/actions/MergeDataAction.java +++ b/numass-main/src/main/java/inr/numass/actions/MergeDataAction.java @@ -21,7 +21,6 @@ import hep.dataforge.data.DataNode; import hep.dataforge.description.NodeDef; import hep.dataforge.description.TypedActionDef; import hep.dataforge.io.ColumnedDataWriter; -import hep.dataforge.io.reports.Reportable; import hep.dataforge.meta.Meta; import hep.dataforge.meta.MetaBuilder; import hep.dataforge.tables.*; @@ -53,13 +52,13 @@ public class MergeDataAction extends ManyToOneAction { } @Override - protected Table execute(Reportable log, String nodeName, Map data, Meta meta) { + protected Table execute(String nodeName, Map data, Meta meta) { Table res = mergeDataSets(nodeName, data.values()); return new ListTable(res.getFormat(), res.sort("Uset", true)); } @Override - protected void afterGroup(Reportable log, String groupName, Meta outputMeta, Table output) { + protected void afterGroup(String groupName, Meta outputMeta, Table output) { OutputStream stream = buildActionOutput(groupName); ColumnedDataWriter.writeDataSet(stream, output, outputMeta.toString()); } diff --git a/numass-main/src/main/java/inr/numass/actions/MonitorCorrectAction.java b/numass-main/src/main/java/inr/numass/actions/MonitorCorrectAction.java index bbd00118..a0f02bc8 100644 --- a/numass-main/src/main/java/inr/numass/actions/MonitorCorrectAction.java +++ b/numass-main/src/main/java/inr/numass/actions/MonitorCorrectAction.java @@ -20,7 +20,6 @@ import hep.dataforge.description.TypedActionDef; import hep.dataforge.description.ValueDef; import hep.dataforge.exceptions.ContentException; import hep.dataforge.io.ColumnedDataWriter; -import hep.dataforge.io.reports.Reportable; import hep.dataforge.meta.Laminate; import hep.dataforge.meta.Meta; import hep.dataforge.tables.DataPoint; @@ -56,13 +55,13 @@ public class MonitorCorrectAction extends OneToOneAction { //FIXME remove from state @Override - protected Table execute(Reportable log, String name, Laminate meta, Table sourceData) throws ContentException { + protected Table execute(String name, Laminate meta, Table sourceData) throws ContentException { double monitor = meta.getDouble("monitorPoint", Double.NaN); TreeMap index = getMonitorIndex(monitor, sourceData); if (index.isEmpty()) { - log.reportError("No monitor points found"); + getReport(name).reportError("No monitor points found"); return sourceData; } double norm = 0; diff --git a/numass-main/src/main/java/inr/numass/actions/PileupSimulationAction.java b/numass-main/src/main/java/inr/numass/actions/PileupSimulationAction.java index d5d25c54..de9405c8 100644 --- a/numass-main/src/main/java/inr/numass/actions/PileupSimulationAction.java +++ b/numass-main/src/main/java/inr/numass/actions/PileupSimulationAction.java @@ -6,9 +6,7 @@ package inr.numass.actions; import hep.dataforge.actions.OneToOneAction; -import hep.dataforge.context.Context; import hep.dataforge.description.TypedActionDef; -import hep.dataforge.io.reports.Reportable; import hep.dataforge.meta.Laminate; import hep.dataforge.meta.Meta; import inr.numass.storage.NMPoint; @@ -16,6 +14,7 @@ import inr.numass.storage.NumassData; import inr.numass.storage.RawNMPoint; import inr.numass.utils.PileUpSimulator; import inr.numass.utils.TritiumUtils; + import java.time.Instant; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -31,7 +30,7 @@ import java.util.Map; public class PileupSimulationAction extends OneToOneAction> { @Override - protected Map execute(Reportable log, String name, Laminate inputMeta, NumassData input) { + protected Map execute(String name, Laminate inputMeta, NumassData input) { int lowerChannel = inputMeta.getInt("lowerChannel", 1); int upperChannel = inputMeta.getInt("upperChannel", RawNMPoint.MAX_CHANEL - 1); diff --git a/numass-main/src/main/java/inr/numass/actions/PrepareDataAction.java b/numass-main/src/main/java/inr/numass/actions/PrepareDataAction.java index d7907d8c..8d534062 100644 --- a/numass-main/src/main/java/inr/numass/actions/PrepareDataAction.java +++ b/numass-main/src/main/java/inr/numass/actions/PrepareDataAction.java @@ -68,7 +68,7 @@ public class PrepareDataAction extends OneToOneAction { } @Override - protected ListTable execute(Reportable log, String name, Laminate meta, NumassData dataFile) { + protected ListTable execute(String name, Laminate meta, NumassData dataFile) { // log.report("File %s started", dataFile.getName()); int upper = meta.getInt("upperWindow", RawNMPoint.MAX_CHANEL - 1); @@ -99,7 +99,7 @@ public class PrepareDataAction extends OneToOneAction { // count rate error after all corrections double crErr = TritiumUtils.countRateWithDeadTimeErr(point, a, b, deadTimeFunction.apply(point)); - double correctionFactor = correction(log, point, meta); + double correctionFactor = correction(getReport(name), point, meta); cr = cr * correctionFactor; crErr = crErr * correctionFactor; diff --git a/numass-main/src/main/java/inr/numass/actions/ReadNumassDataAction.java b/numass-main/src/main/java/inr/numass/actions/ReadNumassDataAction.java index 685a5c6e..02202117 100644 --- a/numass-main/src/main/java/inr/numass/actions/ReadNumassDataAction.java +++ b/numass-main/src/main/java/inr/numass/actions/ReadNumassDataAction.java @@ -16,18 +16,17 @@ package inr.numass.actions; import hep.dataforge.actions.OneToOneAction; -import hep.dataforge.context.Context; import hep.dataforge.data.binary.Binary; import hep.dataforge.description.NodeDef; import hep.dataforge.description.TypedActionDef; import hep.dataforge.description.ValueDef; import hep.dataforge.exceptions.ContentException; -import hep.dataforge.io.reports.Reportable; import hep.dataforge.meta.Laminate; -import static inr.numass.NumassIO.getNumassData; import inr.numass.storage.NMFile; import inr.numass.storage.RawNMFile; +import static inr.numass.NumassIO.getNumassData; + /** * * @author Darksnake @@ -42,7 +41,7 @@ import inr.numass.storage.RawNMFile; public class ReadNumassDataAction extends OneToOneAction { @Override - protected NMFile execute(Reportable log, String name, Laminate meta, Binary source) throws ContentException { + protected NMFile execute(String name, Laminate meta, Binary source) throws ContentException { // log.logString("File '%s' started", source.getName()); RawNMFile raw = getNumassData(source, meta); if (meta.getBoolean("paw", false)) { @@ -54,7 +53,7 @@ public class ReadNumassDataAction extends OneToOneAction { Laminate laminate = new Laminate(meta.getNode("debunch")) .setValueContext(getContext()) .setDescriptor(debunch.getDescriptor()); - raw = debunch.execute(log, name, laminate, raw); + raw = debunch.execute(name, laminate, raw); } NMFile result = new NMFile(raw); diff --git a/numass-main/src/main/java/inr/numass/actions/ShowEnergySpectrumAction.java b/numass-main/src/main/java/inr/numass/actions/ShowEnergySpectrumAction.java index c7b2abe0..e0c567e8 100644 --- a/numass-main/src/main/java/inr/numass/actions/ShowEnergySpectrumAction.java +++ b/numass-main/src/main/java/inr/numass/actions/ShowEnergySpectrumAction.java @@ -6,10 +6,8 @@ package inr.numass.actions; import hep.dataforge.actions.OneToOneAction; -import hep.dataforge.context.Context; import hep.dataforge.description.TypedActionDef; import hep.dataforge.io.ColumnedDataWriter; -import hep.dataforge.io.reports.Reportable; import hep.dataforge.meta.Laminate; import hep.dataforge.meta.Meta; import hep.dataforge.meta.MetaBuilder; @@ -17,21 +15,13 @@ import hep.dataforge.plots.PlotsPlugin; import hep.dataforge.plots.XYPlotFrame; import hep.dataforge.plots.XYPlottable; import hep.dataforge.plots.data.PlottableData; -import hep.dataforge.tables.DataPoint; -import hep.dataforge.tables.ListTable; -import hep.dataforge.tables.MapPoint; -import hep.dataforge.tables.Table; -import hep.dataforge.tables.TableFormatBuilder; -import hep.dataforge.tables.XYAdapter; +import hep.dataforge.tables.*; import hep.dataforge.values.ValueType; import inr.numass.storage.NMPoint; import inr.numass.storage.NumassData; + import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; /** @@ -42,7 +32,7 @@ import java.util.stream.Collectors; public class ShowEnergySpectrumAction extends OneToOneAction { @Override - protected Table execute(Reportable log, String name, Laminate inputMeta, NumassData input) { + protected Table execute(String name, Laminate inputMeta, NumassData input) { int binning = inputMeta.getInt("binning", 20); boolean normalize = inputMeta.getBoolean("normalize", true); List points = input.getNMPoints(); diff --git a/numass-main/src/main/java/inr/numass/actions/ShowLossSpectrumAction.java b/numass-main/src/main/java/inr/numass/actions/ShowLossSpectrumAction.java index cf35326d..701beb34 100644 --- a/numass-main/src/main/java/inr/numass/actions/ShowLossSpectrumAction.java +++ b/numass-main/src/main/java/inr/numass/actions/ShowLossSpectrumAction.java @@ -19,7 +19,6 @@ import hep.dataforge.actions.OneToOneAction; import hep.dataforge.description.TypedActionDef; import hep.dataforge.io.ColumnedDataWriter; import hep.dataforge.io.PrintFunction; -import hep.dataforge.io.reports.Reportable; import hep.dataforge.maths.GridCalculator; import hep.dataforge.maths.NamedMatrix; import hep.dataforge.maths.integration.UnivariateIntegrator; @@ -56,7 +55,6 @@ import java.nio.charset.Charset; import java.util.Arrays; /** - * * @author darksnake */ @TypedActionDef(name = "showLoss", inputType = FitState.class, outputType = FitState.class, @@ -115,7 +113,7 @@ public class ShowLossSpectrumAction extends OneToOneAction { } @Override - protected FitState execute(Reportable log, String name, Laminate meta, FitState input) { + protected FitState execute(String name, Laminate meta, FitState input) { ParamSet pars = input.getParameters(); if (!pars.names().contains(names)) { LoggerFactory.getLogger(getClass()).error("Wrong input FitState. Must be loss spectrum fit."); @@ -127,7 +125,7 @@ public class ShowLossSpectrumAction extends OneToOneAction { XYPlotFrame frame = (XYPlotFrame) PlotsPlugin.buildFrom(getContext()) .buildPlotFrame(getName(), name + ".loss", new MetaBuilder("plot") - .setValue("plotTitle", "Differential scattering crossection for " + name) + .setValue("plotTitle", "Differential scattering crossection for " + name) ); switch (input.getModel().meta().getString("name", "")) { case "scatter-variable": @@ -151,9 +149,9 @@ public class ShowLossSpectrumAction extends OneToOneAction { if (calculateRatio) { threshold = meta.getDouble("ionThreshold", 17); ionRatio = calcultateIonRatio(pars, threshold); - log.report("The ionization ratio (using threshold {}) is {}", threshold, ionRatio); + report(name, "The ionization ratio (using threshold {}) is {}", threshold, ionRatio); ionRatioError = calultateIonRatioError(name, input, threshold); - log.report("the ionization ration standard deviation (using threshold {}) is {}", threshold, ionRatioError); + report(name, "the ionization ration standard deviation (using threshold {}) is {}", threshold, ionRatioError); } if (meta.getBoolean("printResult", false)) { diff --git a/numass-main/src/main/java/inr/numass/actions/SlicingAction.java b/numass-main/src/main/java/inr/numass/actions/SlicingAction.java index ffd18b30..315f52b4 100644 --- a/numass-main/src/main/java/inr/numass/actions/SlicingAction.java +++ b/numass-main/src/main/java/inr/numass/actions/SlicingAction.java @@ -16,23 +16,21 @@ package inr.numass.actions; import hep.dataforge.actions.OneToOneAction; -import hep.dataforge.context.Context; import hep.dataforge.description.TypedActionDef; import hep.dataforge.exceptions.ContentException; import hep.dataforge.io.ColumnedDataWriter; -import hep.dataforge.io.reports.Reportable; import hep.dataforge.meta.Laminate; import hep.dataforge.meta.Meta; import inr.numass.storage.NMFile; import inr.numass.storage.RawNMPoint; +import org.apache.commons.math3.util.Pair; + import java.io.OutputStream; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import org.apache.commons.math3.util.Pair; /** - * * @author Darksnake */ @TypedActionDef(name = "slicing", inputType = NMFile.class, outputType = NMFile.class) @@ -46,7 +44,7 @@ public class SlicingAction extends OneToOneAction { } @Override - protected NMFile execute(Reportable log, String name, Laminate meta, NMFile source) throws ContentException { + protected NMFile execute(String name, Laminate meta, NMFile source) throws ContentException { boolean normalize; Map> slicingConfig; @@ -66,7 +64,7 @@ public class SlicingAction extends OneToOneAction { if (slicingConfig == null) { throw new RuntimeException("Slice configuration not defined"); } - log.report("File {} started", source.getName()); + report(name, "File {} started", source.getName()); SlicedData sData = new SlicedData(source, slicingConfig, normalize); @@ -74,7 +72,7 @@ public class SlicingAction extends OneToOneAction { ColumnedDataWriter.writeDataSet(stream, sData, null); - log.report("File {} completed", source.getName()); + report(name, "File {} completed", source.getName()); return source; } diff --git a/numass-main/src/main/java/inr/numass/actions/SubstractSpectrumAction.java b/numass-main/src/main/java/inr/numass/actions/SubstractSpectrumAction.java index e761d965..e7c27252 100644 --- a/numass-main/src/main/java/inr/numass/actions/SubstractSpectrumAction.java +++ b/numass-main/src/main/java/inr/numass/actions/SubstractSpectrumAction.java @@ -9,26 +9,25 @@ import hep.dataforge.actions.OneToOneAction; import hep.dataforge.description.TypedActionDef; import hep.dataforge.io.ColumnedDataReader; import hep.dataforge.io.ColumnedDataWriter; -import hep.dataforge.io.reports.Reportable; import hep.dataforge.meta.Laminate; import hep.dataforge.tables.DataPoint; import hep.dataforge.tables.ListTable; import hep.dataforge.tables.MapPoint; import hep.dataforge.tables.Table; + import java.io.File; import java.io.IOException; import java.io.OutputStream; import java.util.Optional; /** - * * @author Alexander Nozik */ @TypedActionDef(name = "substractSpectrum", inputType = Table.class, outputType = Table.class, info = "Substract reference spectrum (background)") public class SubstractSpectrumAction extends OneToOneAction { @Override - protected Table execute(Reportable log, String name, Laminate inputMeta, Table input) { + protected Table execute(String name, Laminate inputMeta, Table input) { try { String referencePath = inputMeta.getString("file", "empty.dat"); File referenceFile = getContext().io().getFile(referencePath); @@ -44,7 +43,7 @@ public class SubstractSpectrumAction extends OneToOneAction { pointBuilder.putValue("CR", Math.max(0, point.getDouble("CR") - referencePoint.get().getDouble("CR"))); pointBuilder.putValue("CRerr", Math.sqrt(Math.pow(point.getDouble("CRerr"), 2d) + Math.pow(referencePoint.get().getDouble("CRerr"), 2d))); } else { - log.report("No reference point found for Uset = {}", point.getDouble("Uset")); + report(name, "No reference point found for Uset = {}", point.getDouble("Uset")); } builder.row(pointBuilder.build()); }); diff --git a/numass-main/src/main/java/inr/numass/actions/SummaryAction.java b/numass-main/src/main/java/inr/numass/actions/SummaryAction.java index 30aa46f2..6180e4f6 100644 --- a/numass-main/src/main/java/inr/numass/actions/SummaryAction.java +++ b/numass-main/src/main/java/inr/numass/actions/SummaryAction.java @@ -18,17 +18,13 @@ package inr.numass.actions; import hep.dataforge.actions.GroupBuilder; import hep.dataforge.actions.ManyToOneAction; import hep.dataforge.data.DataNode; -import hep.dataforge.stat.fit.FitState; import hep.dataforge.description.TypedActionDef; import hep.dataforge.io.ColumnedDataWriter; -import hep.dataforge.io.reports.Reportable; import hep.dataforge.meta.Meta; -import hep.dataforge.tables.DataPoint; -import hep.dataforge.tables.ListTable; -import hep.dataforge.tables.MapPoint; -import hep.dataforge.tables.Table; -import hep.dataforge.tables.TableFormat; +import hep.dataforge.stat.fit.FitState; +import hep.dataforge.tables.*; import hep.dataforge.values.Value; + import java.io.OutputStream; import java.util.Arrays; import java.util.List; @@ -57,7 +53,7 @@ public class SummaryAction extends ManyToOneAction { } @Override - protected Table execute(Reportable log, String nodeName, Map input, Meta meta) { + protected Table execute(String nodeName, Map input, Meta meta) { String[] parNames = meta.getStringArray("parnames"); String[] names = new String[2 * parNames.length + 2]; names[0] = "file"; @@ -107,11 +103,11 @@ public class SummaryAction extends ManyToOneAction { } @Override - protected void afterGroup(Reportable log, String groupName, Meta outputMeta, Table output) { + protected void afterGroup(String groupName, Meta outputMeta, Table output) { OutputStream stream = buildActionOutput(groupName); ColumnedDataWriter.writeDataSet(stream, output, groupName); - super.afterGroup(log, groupName, outputMeta, output); + super.afterGroup(groupName, outputMeta, output); } } diff --git a/numass-main/src/main/java/inr/numass/models/FSS.java b/numass-main/src/main/java/inr/numass/models/FSS.java index e6fe3c56..97e385cc 100644 --- a/numass-main/src/main/java/inr/numass/models/FSS.java +++ b/numass-main/src/main/java/inr/numass/models/FSS.java @@ -18,6 +18,7 @@ package inr.numass.models; import hep.dataforge.io.IOUtils; import hep.dataforge.tables.DataPoint; import hep.dataforge.tables.PointSource; + import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; @@ -43,10 +44,10 @@ public class FSS{ norm += p; } if(ps.isEmpty()) { - throw new Error("Error reading FSS FILE. No points."); + throw new RuntimeException("Error reading FSS FILE. No points."); } } catch (FileNotFoundException ex) { - throw new Error("Error reading FSS FILE. File not found."); + throw new RuntimeException("Error reading FSS FILE. File not found."); } } 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 bbbe0cd9..c08180e4 100644 --- a/numass-main/src/main/java/inr/numass/models/LossCalculator.java +++ b/numass-main/src/main/java/inr/numass/models/LossCalculator.java @@ -15,22 +15,24 @@ */ package inr.numass.models; -import hep.dataforge.stat.parametric.FunctionCaching; import hep.dataforge.maths.integration.GaussRuleIntegrator; import hep.dataforge.maths.integration.UnivariateIntegrator; import hep.dataforge.plots.XYPlotFrame; import hep.dataforge.plots.data.PlottableXYFunction; +import hep.dataforge.stat.parametric.FunctionCaching; import hep.dataforge.values.NamedValueSet; -import static java.lang.Math.exp; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import org.apache.commons.math3.analysis.BivariateFunction; import org.apache.commons.math3.analysis.UnivariateFunction; import org.apache.commons.math3.exception.OutOfRangeException; import org.slf4j.LoggerFactory; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static java.lang.Math.exp; + /** * Вычисление произвольного порядка функции рассеяния. Не учитывается * зависимость сечения от энергии электрона @@ -46,7 +48,12 @@ public class LossCalculator { private static final LossCalculator instance = new LossCalculator(); private static final UnivariateIntegrator integrator = new GaussRuleIntegrator(100); + private final Map cache = new HashMap<>(); + private LossCalculator() { + cache.put(1, getSingleScatterFunction()); +// cache.put(2, getDoubleScatterFunction()); + } public static UnivariateFunction getSingleScatterFunction() { final double A1 = 0.204; @@ -196,13 +203,6 @@ public class LossCalculator { } - private final Map cache = new HashMap<>(); - - private LossCalculator() { - cache.put(1, getSingleScatterFunction()); -// cache.put(2, getDoubleScatterFunction()); - } - public List getGunLossProbabilities(double X) { List res = new ArrayList<>(); double prob; @@ -238,17 +238,19 @@ public class LossCalculator { * @param order * @return */ - private synchronized UnivariateFunction getLoss(int order) { + private UnivariateFunction getLoss(int order) { if (order <= 0) { throw new IllegalArgumentException(); } if (cache.containsKey(order)) { return cache.get(order); } else { - LoggerFactory.getLogger(getClass()) - .debug("Scatter cache of order {} not found. Updating", order); - cache.put(order, getNextLoss(getMargin(order), getLoss(order - 1))); - return cache.get(order); + synchronized (this) { + LoggerFactory.getLogger(getClass()) + .debug("Scatter cache of order {} not found. Updating", order); + cache.putIfAbsent(order, getNextLoss(getMargin(order), getLoss(order - 1))); + return cache.get(order); + } } } @@ -325,7 +327,7 @@ public class LossCalculator { } } - public synchronized double getLossValue(int order, double Ei, double Ef) { + public double getLossValue(int order, double Ei, double Ef) { if (Ei - Ef < 5d) { return 0; } else if (Ei - Ef >= getMargin(order)) { diff --git a/numass-main/src/main/java/inr/numass/tasks/GrindCaller.java b/numass-main/src/main/java/inr/numass/tasks/GrindCaller.java index d0a29ffc..6b4c5a88 100644 --- a/numass-main/src/main/java/inr/numass/tasks/GrindCaller.java +++ b/numass-main/src/main/java/inr/numass/tasks/GrindCaller.java @@ -10,7 +10,7 @@ import java.io.File; public class GrindCaller { public static void main(String[] args) throws Exception { - JavaGrindLauncher.buildWorkspace(new File("D:\\Work\\Numass\\sterile2016\\workspace.groovy")).runTask("numass.prepare", "fill_2").computeAll(); + JavaGrindLauncher.buildWorkspace(new File("D:\\Work\\Numass\\sterile2016\\workspace.groovy")).runTask("numass.fitsum", "fill_2").computeAll(); } } diff --git a/numass-main/src/main/java/inr/numass/tasks/NumassFitScanSummaryTask.java b/numass-main/src/main/java/inr/numass/tasks/NumassFitScanSummaryTask.java index 898486fb..804b3bbe 100644 --- a/numass-main/src/main/java/inr/numass/tasks/NumassFitScanSummaryTask.java +++ b/numass-main/src/main/java/inr/numass/tasks/NumassFitScanSummaryTask.java @@ -5,12 +5,14 @@ */ package inr.numass.tasks; +import hep.dataforge.actions.Action; import hep.dataforge.actions.ManyToOneAction; import hep.dataforge.computation.WorkManager; import hep.dataforge.context.Context; import hep.dataforge.data.DataNode; +import hep.dataforge.data.DataSet; import hep.dataforge.description.TypedActionDef; -import hep.dataforge.io.reports.Reportable; +import hep.dataforge.io.ColumnedDataWriter; import hep.dataforge.meta.Meta; import hep.dataforge.stat.fit.FitState; import hep.dataforge.stat.fit.ParamSet; @@ -20,23 +22,27 @@ import hep.dataforge.workspace.GenericTask; import hep.dataforge.workspace.TaskModel; import hep.dataforge.workspace.TaskState; +import java.io.OutputStream; import java.util.Map; /** - * * @author Alexander Nozik */ public class NumassFitScanSummaryTask extends GenericTask { @Override protected void transform(WorkManager.Callback callback, Context context, TaskState state, Meta config) { - state.finish(new FitSummaryAction().withContext(context).run((DataNode) state.getData(), config)); + DataSet.Builder builder = DataSet.builder(Table.class); + Action action = new FitSummaryAction().withContext(context); + state.getData().getNode("fitscan").get().nodeStream().forEach(node -> + builder.putData(node.getName(), action.run((DataNode) node, config).getData())); + state.finish(builder.build()); } @Override protected TaskModel transformModel(TaskModel model) { //Transmit meta as-is - model.dependsOn("numass.fitscan", model.meta()); + model.dependsOn("numass.fitscan", model.meta(), "fitscan"); return model; } @@ -45,11 +51,11 @@ public class NumassFitScanSummaryTask extends GenericTask { return "numass.fitsum"; } - @TypedActionDef(name = "fitSummary", inputType = FitState.class, outputType = Table.class) + @TypedActionDef(name = "sterileSummary", inputType = FitState.class, outputType = Table.class) private class FitSummaryAction extends ManyToOneAction { @Override - protected Table execute(Reportable log, String nodeName, Map input, Meta meta) { + protected Table execute(String nodeName, Map input, Meta meta) { ListTable.Builder builder = new ListTable.Builder("msterile2", "U2", "U2err", "E0", "trap"); input.forEach((key, fitRes) -> { ParamSet pars = fitRes.getParameters(); @@ -59,7 +65,14 @@ public class NumassFitScanSummaryTask extends GenericTask { pars.getValue("E0"), pars.getValue("trap")); }); - return builder.build(); + Table res = builder.build().sort("msterile2", true); + + + OutputStream stream = buildActionOutput(nodeName); + + ColumnedDataWriter.writeDataSet(stream, res, "Sterile neutrino mass scan summary"); + + return res; } } diff --git a/numass-main/src/main/java/inr/numass/tasks/NumassFitScanTask.java b/numass-main/src/main/java/inr/numass/tasks/NumassFitScanTask.java index 1f1cc79d..a4096572 100644 --- a/numass-main/src/main/java/inr/numass/tasks/NumassFitScanTask.java +++ b/numass-main/src/main/java/inr/numass/tasks/NumassFitScanTask.java @@ -9,11 +9,9 @@ import hep.dataforge.actions.Action; import hep.dataforge.computation.WorkManager; import hep.dataforge.context.Context; import hep.dataforge.data.DataNode; -import hep.dataforge.data.DataSet; import hep.dataforge.data.DataTree; import hep.dataforge.meta.Meta; import hep.dataforge.meta.MetaBuilder; -import hep.dataforge.meta.MetaUtils; import hep.dataforge.stat.fit.FitAction; import hep.dataforge.stat.fit.FitState; import hep.dataforge.tables.Table; @@ -30,10 +28,10 @@ public class NumassFitScanTask extends GenericTask { @Override protected void transform(WorkManager.Callback callback, Context context, TaskState state, Meta config) { String scanParameter = config.getString("scanPar", "msterile2"); - Value scanValues = config.getValue("scanValues", Value.of(new String[]{"0.5, 1, 1.5, 2, 2.5, 3"})); - Action action = new FitAction().withContext(context).withParentProcess(callback.workName()); - DataTree.Builder resultBuilder = DataTree.builder(FitState.class); - DataNode sourceNode = state.getData(); + Value scanValues = config.getValue("scanValues", Value.of("[2.5e5, 1e6, 2.25e6, 4e6, 6.25e6, 9e6]")); + Action action = new FitAction().withContext(context).withParentProcess(callback.workName()); + DataTree.Builder resultBuilder = DataTree.builder(FitState.class); + DataNode sourceNode = state.getData().getNode("prepare").get(); if (config.hasNode("merge")) { //use merged data and ignore raw data @@ -41,20 +39,20 @@ public class NumassFitScanTask extends GenericTask { } //do fit + + Meta fitConfig = config.getMeta("fit"); sourceNode.forEachDataWithType(Table.class, data -> { - DataNode res = scanValues.listValue().stream().parallel().map(val -> { - MetaBuilder overrideMeta = new MetaBuilder("override"); + for (int i = 0; i < scanValues.listValue().size(); i++) { + Value val = scanValues.listValue().get(i); + MetaBuilder overrideMeta = new MetaBuilder(fitConfig); overrideMeta.setValue("@resultName", String.format("%s[%s=%s]", data.getName(), scanParameter, val.stringValue())); - MetaBuilder paramMeta = MetaUtils.findNodeByValue(config, "params.param", data.getName(), scanParameter).getBuilder() - .setValue("value", val); - overrideMeta.setNode("params.param", paramMeta); - return action.run(DataNode.of(data.getName(), data, overrideMeta), config); - }).collect( - () -> DataSet.builder(FitState.class), - (DataSet.Builder builder, DataNode node) -> builder.putData(node.getName(), node.getData()), - (DataSet.Builder builder1, DataSet.Builder builder2) -> builder1.putAll(builder2.getDataMap()) - ).build(); - resultBuilder.putData(data.getName(), res.getData()); + + overrideMeta.getNodes("params.param").stream() + .filter(par -> par.getString("name") == scanParameter).forEach(par -> par.setValue("value", val)); +// Data
newData = new Data
(data.getGoal(),data.dataType(),overrideMeta); + DataNode node = action.run(DataNode.of("fit_" + i, data, Meta.empty()), overrideMeta); + resultBuilder.putData(data.getName() + ".fit_" + i, node.getData()); + } }); @@ -64,7 +62,12 @@ public class NumassFitScanTask extends GenericTask { @Override protected TaskModel transformModel(TaskModel model) { //Transmit meta as-is - model.dependsOn("numass.prepare", model.meta()); + MetaBuilder metaBuilder = new MetaBuilder(model.meta()).removeNode("fit"); + if (model.meta().hasNode("filter")) { + model.dependsOn("numass.filter", metaBuilder.build(), "prepare"); + } else { + model.dependsOn("numass.prepare", metaBuilder.build(), "prepare"); + } return model; } diff --git a/numass-main/src/main/java/inr/numass/tasks/NumassPrepareTask.java b/numass-main/src/main/java/inr/numass/tasks/NumassPrepareTask.java index fb287370..a6c4d790 100644 --- a/numass-main/src/main/java/inr/numass/tasks/NumassPrepareTask.java +++ b/numass-main/src/main/java/inr/numass/tasks/NumassPrepareTask.java @@ -49,16 +49,16 @@ public class NumassPrepareTask extends GenericTask { @SuppressWarnings("unchecked") protected void transform(WorkManager.Callback callback, Context context, TaskState state, Meta config) { //acquiring initial data. Data node could not be empty - Meta dataMeta = Template.compileTemplate(config.getNode("data"), config); + Meta dataMeta = config.getNode("data"); DataNode data = runAction(new ReadNumassStorageAction(), callback, context, DataNode.empty(), dataMeta); state.setData("data", data); //preparing table data - Meta prepareMeta = Template.compileTemplate(config.getNode("prepare"), config); + Meta prepareMeta = config.getNode("prepare"); DataNode
tables = runAction(new PrepareDataAction(), callback, context, data, prepareMeta); state.setData("prepare", tables); if (config.hasNode("monitor")) { - Meta monitorMeta = Template.compileTemplate(config.getNode("monitor"), config); + Meta monitorMeta = config.getNode("monitor"); tables = runAction(new MonitorCorrectAction(), callback, context, tables, monitorMeta); state.setData("monitor", tables); } @@ -79,7 +79,7 @@ public class NumassPrepareTask extends GenericTask { } if (config.hasNode("transform")) { - Meta filterMeta = Template.compileTemplate(config.getNode("transform"), config); + Meta filterMeta = config.getNode("transform"); tables = runAction(new TransformTableAction(), callback, context, tables, filterMeta); } diff --git a/numass-main/src/main/java/inr/numass/tasks/NumassTableFilterTask.java b/numass-main/src/main/java/inr/numass/tasks/NumassTableFilterTask.java new file mode 100644 index 00000000..7b3f8b8c --- /dev/null +++ b/numass-main/src/main/java/inr/numass/tasks/NumassTableFilterTask.java @@ -0,0 +1,49 @@ +package inr.numass.tasks; + +import hep.dataforge.actions.OneToOneAction; +import hep.dataforge.computation.WorkManager; +import hep.dataforge.context.Context; +import hep.dataforge.data.DataNode; +import hep.dataforge.description.TypedActionDef; +import hep.dataforge.meta.Laminate; +import hep.dataforge.meta.Meta; +import hep.dataforge.meta.MetaBuilder; +import hep.dataforge.tables.Table; +import hep.dataforge.workspace.GenericTask; +import hep.dataforge.workspace.TaskModel; +import hep.dataforge.workspace.TaskState; + +/** + * Created by darksnake on 13-Aug-16. + */ +public class NumassTableFilterTask extends GenericTask
{ + + @Override + public String getName() { + return "numass.filter"; + } + + @Override + protected void transform(WorkManager.Callback callback, Context context, TaskState state, Meta config) { + DataNode
sourceNode = (DataNode
) state.getData().getNode("prepare").get(); + state.finish(new FilterTableAction().withContext(context).run(sourceNode, config)); + } + + @Override + protected TaskModel transformModel(TaskModel model) { + super.transformModel(model); + MetaBuilder metaBuilder = new MetaBuilder(model.meta()).removeNode("filter"); + model.dependsOn("numass.prepare", metaBuilder.build(), "prepare"); + return model; + } + + @TypedActionDef(name = "filterTable", inputType = Table.class, outputType = Table.class) + private class FilterTableAction extends OneToOneAction { + @Override + protected Table execute(String name, Laminate inputMeta, Table input) { + double uLo = inputMeta.getDouble("filter.from", 0); + double uHi = inputMeta.getDouble("filter.to", Double.POSITIVE_INFINITY); + return input.filter("Uset", uLo, uHi); + } + } +}