From 0b0de20481ac657bfdffecce56f0e3afcc5e2055 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Thu, 23 Nov 2017 18:46:03 +0300 Subject: [PATCH] Fixed numass join sets --- .../java/inr/numass/data/NumassDataUtils.java | 6 +- .../numass/data/api/SimpleNumassPoint.java | 4 +- .../data/storage/NumassStorageFactory.java | 2 +- .../numass/scripts/temp/JoinSpectra.groovy | 64 +++++++++++++++++++ .../numass/scripts/times/AnalyzePoint.groovy | 2 +- .../kotlin/inr/numass/viewer/StorageView.kt | 4 +- 6 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 numass-main/src/main/groovy/inr/numass/scripts/temp/JoinSpectra.groovy diff --git a/numass-core/src/main/java/inr/numass/data/NumassDataUtils.java b/numass-core/src/main/java/inr/numass/data/NumassDataUtils.java index f0f50de8..54db1b25 100644 --- a/numass-core/src/main/java/inr/numass/data/NumassDataUtils.java +++ b/numass-core/src/main/java/inr/numass/data/NumassDataUtils.java @@ -10,9 +10,11 @@ import hep.dataforge.values.Value; import hep.dataforge.values.Values; import inr.numass.data.api.NumassPoint; import inr.numass.data.api.NumassSet; +import inr.numass.data.api.SimpleNumassPoint; import org.jetbrains.annotations.NotNull; import java.util.Collection; +import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; @@ -31,7 +33,9 @@ public class NumassDataUtils { return new NumassSet() { @Override public Stream getPoints() { - return sets.stream().flatMap(NumassSet::getPoints); + Map> points = sets.stream().flatMap(NumassSet::getPoints) + .collect(Collectors.groupingBy(NumassPoint::getVoltage)); + return points.entrySet().stream().map(entry->new SimpleNumassPoint(entry.getKey(),entry.getValue())); } @Override diff --git a/numass-core/src/main/java/inr/numass/data/api/SimpleNumassPoint.java b/numass-core/src/main/java/inr/numass/data/api/SimpleNumassPoint.java index 40765162..b69b4495 100644 --- a/numass-core/src/main/java/inr/numass/data/api/SimpleNumassPoint.java +++ b/numass-core/src/main/java/inr/numass/data/api/SimpleNumassPoint.java @@ -22,13 +22,13 @@ public class SimpleNumassPoint extends MetaHolder implements NumassPoint { * @param voltage * @param blocks */ - public SimpleNumassPoint(double voltage, Collection blocks) { + public SimpleNumassPoint(double voltage, Collection blocks) { this.blocks = new ArrayList<>(blocks); this.blocks.sort(Comparator.comparing(NumassBlock::getStartTime)); super.setMeta(new MetaBuilder("point").setValue(HV_KEY, voltage)); } - public SimpleNumassPoint(Meta meta, Collection blocks) { + public SimpleNumassPoint(Meta meta, Collection blocks) { super(meta); this.blocks = new ArrayList<>(blocks); this.blocks.sort(Comparator.comparing(NumassBlock::getStartTime)); diff --git a/numass-core/src/main/java/inr/numass/data/storage/NumassStorageFactory.java b/numass-core/src/main/java/inr/numass/data/storage/NumassStorageFactory.java index 327a0d3e..ed1ad312 100644 --- a/numass-core/src/main/java/inr/numass/data/storage/NumassStorageFactory.java +++ b/numass-core/src/main/java/inr/numass/data/storage/NumassStorageFactory.java @@ -29,7 +29,7 @@ public class NumassStorageFactory implements StorageType { */ public static NumassStorage buildLocal(File file) { return new NumassStorage(Global.instance(), - new MetaBuilder("storage").setValue("path", file.toURI())); + new MetaBuilder("storage").setValue("path", file.toPath())); } @Override diff --git a/numass-main/src/main/groovy/inr/numass/scripts/temp/JoinSpectra.groovy b/numass-main/src/main/groovy/inr/numass/scripts/temp/JoinSpectra.groovy new file mode 100644 index 00000000..6698c012 --- /dev/null +++ b/numass-main/src/main/groovy/inr/numass/scripts/temp/JoinSpectra.groovy @@ -0,0 +1,64 @@ +package inr.numass.scripts.temp + +import hep.dataforge.context.Context +import hep.dataforge.context.Global +import hep.dataforge.description.DescriptorUtils +import hep.dataforge.fx.plots.PlotManager +import hep.dataforge.grind.GrindShell +import hep.dataforge.grind.helpers.PlotHelper +import hep.dataforge.meta.Meta +import hep.dataforge.plots.PlotFrame +import hep.dataforge.plots.data.DataPlot +import hep.dataforge.tables.ColumnTable +import hep.dataforge.tables.Table +import hep.dataforge.tables.XYAdapter +import inr.numass.NumassPlugin +import inr.numass.data.NumassDataUtils +import inr.numass.data.analyzers.SmartAnalyzer +import inr.numass.data.api.NumassAnalyzer +import inr.numass.data.api.NumassSet +import inr.numass.data.storage.NumassStorage +import inr.numass.data.storage.NumassStorageFactory + +Context ctx = Global.instance() +ctx.getPluginManager().load(PlotManager) +ctx.getPluginManager().load(NumassPlugin.class) + + +Table.metaClass.dt{double dt = 6.5 -> + double totalCR = delegate.getColumn(NumassAnalyzer.COUNT_RATE_KEY).stream().mapToDouble { it.doubleValue() }.sum() +// long totalCount = delegate.getColumn(NumassAnalyzer.COUNT_RATE_KEY).stream().mapToLong() { it.longValue() }.sum() +// double time = totalCount / totalCR + double factor = 1d / (1d - dt * 1e-6 * totalCR) + return ColumnTable.copy(delegate) + .replaceColumn(NumassAnalyzer.COUNT_RATE_KEY){it.getDouble(NumassAnalyzer.COUNT_RATE_KEY)*factor} + .replaceColumn(NumassAnalyzer.COUNT_RATE_ERROR_KEY){it.getDouble(NumassAnalyzer.COUNT_RATE_ERROR_KEY)*factor} +} + + +new GrindShell(ctx).eval { + File rootDir = new File("D:\\Work\\Numass\\data\\2017_11\\Fill_1") + + NumassStorage storage = NumassStorageFactory.buildLocal(rootDir); + + NumassSet joined = NumassDataUtils.join("sum", storage.loaders() + .findAll { it instanceof NumassSet } + .collect { it as NumassSet } + ) + + PlotFrame frame = (plots as PlotHelper).getManager().getPlotFrame("test", "spectra") + + NumassAnalyzer analyzer = new SmartAnalyzer(); + + frame.plots.setDescriptor(DescriptorUtils.buildDescriptor(DataPlot)) + frame.plots.configure(showErrors: false, showSymbol: false, showLine: true, connection: "step") + + joined.points.filter { it.voltage in [14000d, 15000d, 16000d, 17000d, 18000d] }.forEach { + Table spectrum = NumassDataUtils.spectrumWithBinning(analyzer.getSpectrum(it, Meta.empty()), 20).dt() + frame.add(DataPlot.plot( + it.voltage.toString(), + new XYAdapter(NumassAnalyzer.CHANNEL_KEY, NumassAnalyzer.COUNT_RATE_KEY, NumassAnalyzer.COUNT_RATE_ERROR_KEY), + spectrum)) + } + +} \ No newline at end of file diff --git a/numass-main/src/main/groovy/inr/numass/scripts/times/AnalyzePoint.groovy b/numass-main/src/main/groovy/inr/numass/scripts/times/AnalyzePoint.groovy index 64dd9eff..8dfac6c1 100644 --- a/numass-main/src/main/groovy/inr/numass/scripts/times/AnalyzePoint.groovy +++ b/numass-main/src/main/groovy/inr/numass/scripts/times/AnalyzePoint.groovy @@ -26,7 +26,7 @@ ctx.getPluginManager().load(PlotManager) ctx.getPluginManager().load(NumassPlugin.class) new GrindShell(ctx).eval { - File rootDir = new File("D:\\Work\\Numass\\data\\2017_05\\Fill_3") + File rootDir = new File("D:\\Work\\Numass\\data\\2017_05\\Fill_2") NumassStorage storage = NumassStorageFactory.buildLocal(rootDir); diff --git a/numass-viewer/src/main/kotlin/inr/numass/viewer/StorageView.kt b/numass-viewer/src/main/kotlin/inr/numass/viewer/StorageView.kt index ba343ce7..9f1488a3 100644 --- a/numass-viewer/src/main/kotlin/inr/numass/viewer/StorageView.kt +++ b/numass-viewer/src/main/kotlin/inr/numass/viewer/StorageView.kt @@ -36,7 +36,7 @@ import kotlin.streams.toList class StorageView(private val context: Context = Global.instance()) : View(title = "Numass storage", icon = ImageView(dfIcon)) { - val storageProperty = SimpleObjectProperty() + val storageProperty = SimpleObjectProperty() var storage by storageProperty @@ -123,7 +123,7 @@ class StorageView(private val context: Context = Global.instance()) : View(title togglebutton("Console") { isSelected = false LogFragment().apply { - addLogHandler(storage.logger) + addLogHandler(context.logger) bindWindow(selectedProperty()) } }