Analyzer fix

This commit is contained in:
Alexander Nozik 2017-11-23 21:40:12 +03:00
parent 0b0de20481
commit 8e32cb7897
3 changed files with 57 additions and 22 deletions

View File

@ -127,7 +127,7 @@ public class NumassDataUtils {
}).forEach(row -> { }).forEach(row -> {
count.addAndGet(row.getValue(COUNT_KEY, 0).longValue()); count.addAndGet(row.getValue(COUNT_KEY, 0).longValue());
countRate.accumulateAndGet(row.getDouble(COUNT_RATE_KEY, 0), (d1, d2) -> d1 + d2); countRate.accumulateAndGet(row.getDouble(COUNT_RATE_KEY, 0), (d1, d2) -> d1 + d2);
countRateDispersion.accumulateAndGet(row.getDouble(COUNT_RATE_ERROR_KEY, 0), (d1, d2) -> d1 + d2); countRateDispersion.accumulateAndGet(Math.pow(row.getDouble(COUNT_RATE_ERROR_KEY, 0),2), (d1, d2) -> d1 + d2);
}); });
int bin = Math.min(binSize, upChannel - chan); int bin = Math.min(binSize, upChannel - chan);
builder.row((double) chan + (double) bin / 2d, count.get(), countRate.get(), Math.sqrt(countRateDispersion.get()), bin); builder.row((double) chan + (double) bin / 2d, count.get(), countRate.get(), Math.sqrt(countRateDispersion.get()), bin);

View File

@ -7,11 +7,14 @@ import hep.dataforge.tables.ValueMap;
import hep.dataforge.values.Value; import hep.dataforge.values.Value;
import hep.dataforge.values.ValueType; import hep.dataforge.values.ValueType;
import hep.dataforge.values.Values; import hep.dataforge.values.Values;
import inr.numass.data.api.NumassAnalyzer;
import inr.numass.data.api.NumassBlock; import inr.numass.data.api.NumassBlock;
import inr.numass.data.api.NumassEvent;
import inr.numass.data.api.SignalProcessor; import inr.numass.data.api.SignalProcessor;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.Map; import java.util.Map;
import java.util.stream.Stream;
/** /**
* An analyzer dispatcher which uses different analyzer for different meta * An analyzer dispatcher which uses different analyzer for different meta
@ -32,35 +35,44 @@ public class SmartAnalyzer extends AbstractAnalyzer {
public SmartAnalyzer() { public SmartAnalyzer() {
} }
@Override private NumassAnalyzer getAnalyzer(Meta config){
public Values analyze(NumassBlock block, Meta config) {
if (config.hasValue("type")) { if (config.hasValue("type")) {
switch (config.getString("type")) { switch (config.getString("type")) {
case "simple": case "simple":
return simpleAnalyzer.analyze(block, config); return simpleAnalyzer;
case "time": case "time":
return timeAnalyzer.analyze(block, config); return timeAnalyzer;
case "debunch": case "debunch":
return debunchAnalyzer.analyze(block, config); return debunchAnalyzer;
default: default:
throw new IllegalArgumentException("Analyzer not found"); throw new IllegalArgumentException("Analyzer not found");
} }
} else { } else {
int t0 = getT0(block, config); if(config.hasValue("t0")||config.hasValue("t0")){
if (t0 == 0) { return timeAnalyzer;
Map<String, Value> map = simpleAnalyzer.analyze(block, config).asMap();
map.putIfAbsent(TimeAnalyzer.T0_KEY, Value.of(0d));
return new ValueMap(map);
} else { } else {
return timeAnalyzer.analyze(block, config.getBuilder().putValue(TimeAnalyzer.T0_KEY, t0)); return simpleAnalyzer;
} }
} }
} }
@Override
public Values analyze(NumassBlock block, Meta config) {
NumassAnalyzer analyzer = getAnalyzer(config);
Map<String, Value> map = analyzer.analyze(block, config).asMap();
map.putIfAbsent(TimeAnalyzer.T0_KEY, Value.of(0d));
return new ValueMap(map);
}
private double estimateCountRate(NumassBlock block) { private double estimateCountRate(NumassBlock block) {
return (double) block.getEvents().count() / block.getLength().toMillis() * 1000; return (double) block.getEvents().count() / block.getLength().toMillis() * 1000;
} }
@Override
public Stream<NumassEvent> getEvents(NumassBlock block, Meta config) {
return getAnalyzer(config).getEvents(block, config);
}
@ValueDef(name = "t0", type = ValueType.NUMBER, info = "Constant t0 cut") @ValueDef(name = "t0", type = ValueType.NUMBER, info = "Constant t0 cut")
@ValueDef(name = "t0.crFraction", type = ValueType.NUMBER, info = "The relative fraction of events that should be removed by time cut") @ValueDef(name = "t0.crFraction", type = ValueType.NUMBER, info = "The relative fraction of events that should be removed by time cut")
@ValueDef(name = "t0.min", type = ValueType.NUMBER, def = "0", info = "Minimal t0") @ValueDef(name = "t0.min", type = ValueType.NUMBER, def = "0", info = "Minimal t0")

View File

@ -4,9 +4,9 @@ import hep.dataforge.context.Context
import hep.dataforge.context.Global import hep.dataforge.context.Global
import hep.dataforge.description.DescriptorUtils import hep.dataforge.description.DescriptorUtils
import hep.dataforge.fx.plots.PlotManager import hep.dataforge.fx.plots.PlotManager
import hep.dataforge.grind.Grind
import hep.dataforge.grind.GrindShell import hep.dataforge.grind.GrindShell
import hep.dataforge.grind.helpers.PlotHelper import hep.dataforge.grind.helpers.PlotHelper
import hep.dataforge.meta.Meta
import hep.dataforge.plots.PlotFrame import hep.dataforge.plots.PlotFrame
import hep.dataforge.plots.data.DataPlot import hep.dataforge.plots.data.DataPlot
import hep.dataforge.tables.ColumnTable import hep.dataforge.tables.ColumnTable
@ -25,14 +25,22 @@ ctx.getPluginManager().load(PlotManager)
ctx.getPluginManager().load(NumassPlugin.class) ctx.getPluginManager().load(NumassPlugin.class)
Table.metaClass.dt{double dt = 6.5 -> Table.metaClass.withBinning { int binning ->
return NumassDataUtils.spectrumWithBinning(delegate, binning)
}
Table.metaClass.withDeadTime { double dt = 6.5 ->
double totalCR = delegate.getColumn(NumassAnalyzer.COUNT_RATE_KEY).stream().mapToDouble { it.doubleValue() }.sum() 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() // long totalCount = delegate.getColumn(NumassAnalyzer.COUNT_RATE_KEY).stream().mapToLong() { it.longValue() }.sum()
// double time = totalCount / totalCR // double time = totalCount / totalCR
double factor = 1d / (1d - dt * 1e-6 * totalCR) double factor = 1d / (1d - dt * 1e-6 * totalCR)
return ColumnTable.copy(delegate) return ColumnTable.copy(delegate)
.replaceColumn(NumassAnalyzer.COUNT_RATE_KEY){it.getDouble(NumassAnalyzer.COUNT_RATE_KEY)*factor} .replaceColumn(NumassAnalyzer.COUNT_RATE_KEY) {
.replaceColumn(NumassAnalyzer.COUNT_RATE_ERROR_KEY){it.getDouble(NumassAnalyzer.COUNT_RATE_ERROR_KEY)*factor} it.getDouble(NumassAnalyzer.COUNT_RATE_KEY) * factor
}
.replaceColumn(NumassAnalyzer.COUNT_RATE_ERROR_KEY) {
it.getDouble(NumassAnalyzer.COUNT_RATE_ERROR_KEY) * factor
}
} }
@ -46,19 +54,34 @@ new GrindShell(ctx).eval {
.collect { it as NumassSet } .collect { it as NumassSet }
) )
PlotFrame frame = (plots as PlotHelper).getManager().getPlotFrame("test", "spectra")
NumassAnalyzer analyzer = new SmartAnalyzer(); NumassAnalyzer analyzer = new SmartAnalyzer();
def adapter = new XYAdapter(NumassAnalyzer.CHANNEL_KEY, NumassAnalyzer.COUNT_RATE_KEY, NumassAnalyzer.COUNT_RATE_ERROR_KEY)
def t0 = 15
PlotFrame frame = (plots as PlotHelper).getManager().getPlotFrame("test", "spectra")
frame.plots.setDescriptor(DescriptorUtils.buildDescriptor(DataPlot)) frame.plots.setDescriptor(DescriptorUtils.buildDescriptor(DataPlot))
frame.plots.configure(showErrors: false, showSymbol: false, showLine: true, connection: "step") frame.plots.configure(showErrors: false, showSymbol: false, showLine: true, connection: "step")
joined.points.filter { it.voltage in [14000d, 15000d, 16000d, 17000d, 18000d] }.forEach { joined.points.filter { it.voltage in [14000d, 15000d, 16000d, 17000d, 18000d] }.forEach {
Table spectrum = NumassDataUtils.spectrumWithBinning(analyzer.getSpectrum(it, Meta.empty()), 20).dt() //Table spectrum = analyzer.getSpectrum(it, Meta.empty()).withBinning(20).withDeadTime()
frame.add(DataPlot.plot( Table spectrum = analyzer.getSpectrum(it, Grind.buildMeta(t0: t0*1000)).withBinning(20).withDeadTime(t0)
it.voltage.toString(), frame.add(DataPlot.plot(it.voltage.toString(), adapter, spectrum))
new XYAdapter(NumassAnalyzer.CHANNEL_KEY, NumassAnalyzer.COUNT_RATE_KEY, NumassAnalyzer.COUNT_RATE_ERROR_KEY),
spectrum))
} }
// def point = joined.points.find { it.voltage == 14000d } as NumassPoint
// PlotFrame pointFrame = (plots as PlotHelper).getManager().getPlotFrame("test", "14000")
//
// pointFrame.plots.setDescriptor(DescriptorUtils.buildDescriptor(DataPlot))
// pointFrame.plots.configure(showErrors: false, showSymbol: false, showLine: true, connection: "step")
//
// [0, 5, 10,15,20].forEach{
// Table spectrum = analyzer.getSpectrum(point, Grind.buildMeta(t0: it*1000)).withBinning(20).withDeadTime(it)
// pointFrame.add(DataPlot.plot(it.toString(), adapter, spectrum))
// }
} }