Analyzer fix
This commit is contained in:
parent
0b0de20481
commit
8e32cb7897
@ -127,7 +127,7 @@ public class NumassDataUtils {
|
||||
}).forEach(row -> {
|
||||
count.addAndGet(row.getValue(COUNT_KEY, 0).longValue());
|
||||
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);
|
||||
builder.row((double) chan + (double) bin / 2d, count.get(), countRate.get(), Math.sqrt(countRateDispersion.get()), bin);
|
||||
|
@ -7,11 +7,14 @@ import hep.dataforge.tables.ValueMap;
|
||||
import hep.dataforge.values.Value;
|
||||
import hep.dataforge.values.ValueType;
|
||||
import hep.dataforge.values.Values;
|
||||
import inr.numass.data.api.NumassAnalyzer;
|
||||
import inr.numass.data.api.NumassBlock;
|
||||
import inr.numass.data.api.NumassEvent;
|
||||
import inr.numass.data.api.SignalProcessor;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* An analyzer dispatcher which uses different analyzer for different meta
|
||||
@ -32,35 +35,44 @@ public class SmartAnalyzer extends AbstractAnalyzer {
|
||||
public SmartAnalyzer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Values analyze(NumassBlock block, Meta config) {
|
||||
private NumassAnalyzer getAnalyzer(Meta config){
|
||||
if (config.hasValue("type")) {
|
||||
switch (config.getString("type")) {
|
||||
case "simple":
|
||||
return simpleAnalyzer.analyze(block, config);
|
||||
return simpleAnalyzer;
|
||||
case "time":
|
||||
return timeAnalyzer.analyze(block, config);
|
||||
return timeAnalyzer;
|
||||
case "debunch":
|
||||
return debunchAnalyzer.analyze(block, config);
|
||||
return debunchAnalyzer;
|
||||
default:
|
||||
throw new IllegalArgumentException("Analyzer not found");
|
||||
}
|
||||
} else {
|
||||
int t0 = getT0(block, config);
|
||||
if (t0 == 0) {
|
||||
Map<String, Value> map = simpleAnalyzer.analyze(block, config).asMap();
|
||||
map.putIfAbsent(TimeAnalyzer.T0_KEY, Value.of(0d));
|
||||
return new ValueMap(map);
|
||||
if(config.hasValue("t0")||config.hasValue("t0")){
|
||||
return timeAnalyzer;
|
||||
} 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) {
|
||||
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.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")
|
||||
|
@ -4,9 +4,9 @@ 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.Grind
|
||||
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
|
||||
@ -25,14 +25,22 @@ ctx.getPluginManager().load(PlotManager)
|
||||
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()
|
||||
// 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}
|
||||
.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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -46,19 +54,34 @@ new GrindShell(ctx).eval {
|
||||
.collect { it as NumassSet }
|
||||
)
|
||||
|
||||
PlotFrame frame = (plots as PlotHelper).getManager().getPlotFrame("test", "spectra")
|
||||
|
||||
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.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))
|
||||
//Table spectrum = analyzer.getSpectrum(it, Meta.empty()).withBinning(20).withDeadTime()
|
||||
Table spectrum = analyzer.getSpectrum(it, Grind.buildMeta(t0: t0*1000)).withBinning(20).withDeadTime(t0)
|
||||
frame.add(DataPlot.plot(it.voltage.toString(), adapter, 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))
|
||||
// }
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user