Fixed numass join sets

This commit is contained in:
Alexander Nozik 2017-11-23 18:46:03 +03:00
parent 7361f7a875
commit 0b0de20481
6 changed files with 75 additions and 7 deletions

View File

@ -10,9 +10,11 @@ import hep.dataforge.values.Value;
import hep.dataforge.values.Values; import hep.dataforge.values.Values;
import inr.numass.data.api.NumassPoint; import inr.numass.data.api.NumassPoint;
import inr.numass.data.api.NumassSet; import inr.numass.data.api.NumassSet;
import inr.numass.data.api.SimpleNumassPoint;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
@ -31,7 +33,9 @@ public class NumassDataUtils {
return new NumassSet() { return new NumassSet() {
@Override @Override
public Stream<NumassPoint> getPoints() { public Stream<NumassPoint> getPoints() {
return sets.stream().flatMap(NumassSet::getPoints); Map<Double,List<NumassPoint>> points = sets.stream().flatMap(NumassSet::getPoints)
.collect(Collectors.groupingBy(NumassPoint::getVoltage));
return points.entrySet().stream().map(entry->new SimpleNumassPoint(entry.getKey(),entry.getValue()));
} }
@Override @Override

View File

@ -22,13 +22,13 @@ public class SimpleNumassPoint extends MetaHolder implements NumassPoint {
* @param voltage * @param voltage
* @param blocks * @param blocks
*/ */
public SimpleNumassPoint(double voltage, Collection<NumassBlock> blocks) { public SimpleNumassPoint(double voltage, Collection<? extends NumassBlock> blocks) {
this.blocks = new ArrayList<>(blocks); this.blocks = new ArrayList<>(blocks);
this.blocks.sort(Comparator.comparing(NumassBlock::getStartTime)); this.blocks.sort(Comparator.comparing(NumassBlock::getStartTime));
super.setMeta(new MetaBuilder("point").setValue(HV_KEY, voltage)); super.setMeta(new MetaBuilder("point").setValue(HV_KEY, voltage));
} }
public SimpleNumassPoint(Meta meta, Collection<NumassBlock> blocks) { public SimpleNumassPoint(Meta meta, Collection<? extends NumassBlock> blocks) {
super(meta); super(meta);
this.blocks = new ArrayList<>(blocks); this.blocks = new ArrayList<>(blocks);
this.blocks.sort(Comparator.comparing(NumassBlock::getStartTime)); this.blocks.sort(Comparator.comparing(NumassBlock::getStartTime));

View File

@ -29,7 +29,7 @@ public class NumassStorageFactory implements StorageType {
*/ */
public static NumassStorage buildLocal(File file) { public static NumassStorage buildLocal(File file) {
return new NumassStorage(Global.instance(), return new NumassStorage(Global.instance(),
new MetaBuilder("storage").setValue("path", file.toURI())); new MetaBuilder("storage").setValue("path", file.toPath()));
} }
@Override @Override

View File

@ -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))
}
}

View File

@ -26,7 +26,7 @@ ctx.getPluginManager().load(PlotManager)
ctx.getPluginManager().load(NumassPlugin.class) ctx.getPluginManager().load(NumassPlugin.class)
new GrindShell(ctx).eval { 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); NumassStorage storage = NumassStorageFactory.buildLocal(rootDir);

View File

@ -36,7 +36,7 @@ import kotlin.streams.toList
class StorageView(private val context: Context = Global.instance()) : View(title = "Numass storage", icon = ImageView(dfIcon)) { class StorageView(private val context: Context = Global.instance()) : View(title = "Numass storage", icon = ImageView(dfIcon)) {
val storageProperty = SimpleObjectProperty<Storage>() val storageProperty = SimpleObjectProperty<Storage?>()
var storage by storageProperty var storage by storageProperty
@ -123,7 +123,7 @@ class StorageView(private val context: Context = Global.instance()) : View(title
togglebutton("Console") { togglebutton("Console") {
isSelected = false isSelected = false
LogFragment().apply { LogFragment().apply {
addLogHandler(storage.logger) addLogHandler(context.logger)
bindWindow(selectedProperty()) bindWindow(selectedProperty())
} }
} }