Fixed numass join sets
This commit is contained in:
parent
7361f7a875
commit
0b0de20481
@ -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<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
|
||||
|
@ -22,13 +22,13 @@ public class SimpleNumassPoint extends MetaHolder implements NumassPoint {
|
||||
* @param voltage
|
||||
* @param blocks
|
||||
*/
|
||||
public SimpleNumassPoint(double voltage, Collection<NumassBlock> blocks) {
|
||||
public SimpleNumassPoint(double voltage, Collection<? extends NumassBlock> 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<NumassBlock> blocks) {
|
||||
public SimpleNumassPoint(Meta meta, Collection<? extends NumassBlock> blocks) {
|
||||
super(meta);
|
||||
this.blocks = new ArrayList<>(blocks);
|
||||
this.blocks.sort(Comparator.comparing(NumassBlock::getStartTime));
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
|
||||
|
@ -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<Storage>()
|
||||
val storageProperty = SimpleObjectProperty<Storage?>()
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user