Corrections redesign

This commit is contained in:
Alexander Nozik 2017-08-10 22:12:21 +03:00
parent 27312b721f
commit 7cdd4286aa
12 changed files with 58 additions and 45 deletions

View File

@ -18,8 +18,10 @@ import static inr.numass.data.api.NumassPoint.HV_KEY;
* Created by darksnake on 11.07.2017. * Created by darksnake on 11.07.2017.
*/ */
public abstract class AbstractAnalyzer implements NumassAnalyzer { public abstract class AbstractAnalyzer implements NumassAnalyzer {
public static String[] NAME_LIST = {LENGTH_KEY, COUNT_KEY, COUNT_RATE_KEY, COUNT_RATE_ERROR_KEY, "window", "timestamp"}; public static String WINDOW_KEY = "window";
public static String[] NAME_LIST_WITH_HV = {HV_KEY, LENGTH_KEY, COUNT_KEY, COUNT_RATE_KEY, COUNT_RATE_ERROR_KEY, "window", "timestamp"};
public static String[] NAME_LIST = {LENGTH_KEY, COUNT_KEY, COUNT_RATE_KEY, COUNT_RATE_ERROR_KEY, WINDOW_KEY, "timestamp"};
public static String[] NAME_LIST_WITH_HV = {HV_KEY, LENGTH_KEY, COUNT_KEY, COUNT_RATE_KEY, COUNT_RATE_ERROR_KEY, WINDOW_KEY, "timestamp"};
@Nullable @Nullable
private final SignalProcessor processor; private final SignalProcessor processor;
@ -40,17 +42,25 @@ public abstract class AbstractAnalyzer implements NumassAnalyzer {
* @return * @return
*/ */
public Stream<NumassEvent> getEvents(NumassBlock block, Meta config) { public Stream<NumassEvent> getEvents(NumassBlock block, Meta config) {
int loChannel = config.getInt("window.lo", 0);
int upChannel = config.getInt("window.up", Integer.MAX_VALUE);
Stream<NumassEvent> res = getAllEvents(block).filter(event -> {
short channel = event.getChanel();
return channel >= loChannel && channel < upChannel;
});
if (config.getBoolean("sort", false)) {
res = res.sorted(Comparator.comparing(NumassEvent::getTimeOffset));
}
return res;
}
protected Stream<NumassEvent> getAllEvents(NumassBlock block){
if (block.getFrames().count() == 0) { if (block.getFrames().count() == 0) {
return block.getEvents(); return block.getEvents();
} else if (getProcessor() == null) { } else if (getProcessor() == null) {
throw new IllegalArgumentException("Signal processor needed to analyze frames"); throw new IllegalArgumentException("Signal processor needed to analyze frames");
} else { } else {
//TODO return Stream.concat(block.getEvents(), block.getFrames().flatMap(getProcessor()::analyze));
Stream<NumassEvent> res = Stream.concat(block.getEvents(), block.getFrames().flatMap(getProcessor()::analyze));
if (config.getBoolean("sort", false)) {
res = res.sorted(Comparator.comparing(NumassEvent::getTimeOffset));
}
return res;
} }
} }
@ -63,7 +73,7 @@ public abstract class AbstractAnalyzer implements NumassAnalyzer {
.addNumber(COUNT_KEY) .addNumber(COUNT_KEY)
.addNumber(COUNT_RATE_KEY, Y_VALUE_KEY) .addNumber(COUNT_RATE_KEY, Y_VALUE_KEY)
.addNumber(COUNT_RATE_ERROR_KEY, Y_ERROR_KEY) .addNumber(COUNT_RATE_ERROR_KEY, Y_ERROR_KEY)
.addColumn("window") .addColumn(WINDOW_KEY)
.addTime() .addTime()
.build(); .build();

View File

@ -4,13 +4,10 @@ import hep.dataforge.meta.Meta;
import hep.dataforge.tables.ValueMap; import hep.dataforge.tables.ValueMap;
import hep.dataforge.values.Values; import hep.dataforge.values.Values;
import inr.numass.data.api.NumassBlock; import inr.numass.data.api.NumassBlock;
import inr.numass.data.api.NumassEvent;
import inr.numass.data.api.NumassPoint; import inr.numass.data.api.NumassPoint;
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.stream.Stream;
/** /**
* A simple event counter * A simple event counter
* Created by darksnake on 07.07.2017. * Created by darksnake on 07.07.2017.
@ -24,15 +21,12 @@ public class SimpleAnalyzer extends AbstractAnalyzer {
public SimpleAnalyzer() { public SimpleAnalyzer() {
} }
public Stream<NumassEvent> getEventStream(NumassBlock block, int loChannel, int upChannel) {
return getEvents(block, Meta.empty()).filter(it -> it.getChanel() >= loChannel && it.getChanel() < upChannel);
}
@Override @Override
public Values analyze(NumassBlock block, Meta config) { public Values analyze(NumassBlock block, Meta config) {
int loChannel = config.getInt("window.lo", 0); int loChannel = config.getInt("window.lo", 0);
int upChannel = config.getInt("window.up", Integer.MAX_VALUE); int upChannel = config.getInt("window.up", Integer.MAX_VALUE);
long count = getEventStream(block, loChannel, upChannel).count(); long count = getEvents(block, config).count();
double countRate = (double) count / block.getLength().toMillis() * 1000; double countRate = (double) count / block.getLength().toMillis() * 1000;
double countRateError = Math.sqrt((double) count) / block.getLength().toMillis() * 1000; double countRateError = Math.sqrt((double) count) / block.getLength().toMillis() * 1000;
@ -43,7 +37,7 @@ public class SimpleAnalyzer extends AbstractAnalyzer {
count, count,
countRate, countRate,
countRateError, countRateError,
new int[]{loChannel, upChannel}, new Integer[]{loChannel, upChannel},
block.getStartTime()); block.getStartTime());
} else { } else {
return ValueMap.of(NAME_LIST, return ValueMap.of(NAME_LIST,
@ -51,7 +45,7 @@ public class SimpleAnalyzer extends AbstractAnalyzer {
count, count,
countRate, countRate,
countRateError, countRateError,
new int[]{loChannel, upChannel}, new Integer[]{loChannel, upChannel},
block.getStartTime()); block.getStartTime());
} }
} }

View File

@ -37,10 +37,6 @@ public class TimeAnalyzer extends AbstractAnalyzer {
AtomicLong totalT = new AtomicLong(0); AtomicLong totalT = new AtomicLong(0);
getEventsWithDelay(block, config) getEventsWithDelay(block, config)
.filter(pair -> {
short channel = pair.getKey().getChanel();
return channel >= loChannel && channel < upChannel;
})
.forEach(pair -> { .forEach(pair -> {
totalN.incrementAndGet(); totalN.incrementAndGet();
//TODO add progress listener here //TODO add progress listener here
@ -59,7 +55,7 @@ public class TimeAnalyzer extends AbstractAnalyzer {
count, count,
countRate, countRate,
countRateError, countRateError,
new int[]{loChannel, upChannel}, new Integer[]{loChannel, upChannel},
block.getStartTime()); block.getStartTime());
} else { } else {
return ValueMap.of(NAME_LIST, return ValueMap.of(NAME_LIST,
@ -67,7 +63,7 @@ public class TimeAnalyzer extends AbstractAnalyzer {
count, count,
countRate, countRate,
countRateError, countRateError,
new int[]{loChannel, upChannel}, new Integer[]{loChannel, upChannel},
block.getStartTime() block.getStartTime()
); );
} }

View File

@ -55,7 +55,7 @@ public interface NumassAnalyzer {
* @param block * @param block
* @return * @return
*/ */
Stream<NumassEvent> getEvents(NumassBlock block, Meta config); Stream<NumassEvent> getEvents(NumassBlock block, Meta meta);
/** /**
* Analyze the whole set. And return results as a table * Analyze the whole set. And return results as a table

View File

@ -33,6 +33,8 @@ import hep.dataforge.stat.models.XYModel;
import hep.dataforge.tables.PointAdapter; import hep.dataforge.tables.PointAdapter;
import hep.dataforge.tables.XYAdapter; import hep.dataforge.tables.XYAdapter;
import inr.numass.actions.*; import inr.numass.actions.*;
import inr.numass.data.api.NumassAnalyzer;
import inr.numass.data.api.NumassPoint;
import inr.numass.models.*; import inr.numass.models.*;
import inr.numass.models.sterile.SterileNeutrinoSpectrum; import inr.numass.models.sterile.SterileNeutrinoSpectrum;
import inr.numass.tasks.*; import inr.numass.tasks.*;
@ -296,7 +298,7 @@ public class NumassPlugin extends BasicPlugin {
if (an.hasMeta(PointAdapter.DATA_ADAPTER_KEY)) { if (an.hasMeta(PointAdapter.DATA_ADAPTER_KEY)) {
return new XYAdapter(an.getMeta(PointAdapter.DATA_ADAPTER_KEY)); return new XYAdapter(an.getMeta(PointAdapter.DATA_ADAPTER_KEY));
} else { } else {
return new XYAdapter("Uread", "CR", "CRerr"); return new XYAdapter(NumassPoint.HV_KEY, NumassAnalyzer.COUNT_RATE_KEY, NumassAnalyzer.COUNT_RATE_ERROR_KEY);
} }
} }
} }

View File

@ -34,8 +34,8 @@ import java.util.*;
/** /**
* @author Darksnake * @author Darksnake
*/ */
@TypedActionDef(name = "merge", inputType = Table.class, outputType = Table.class, info = "Merge different numass data files into one.") @TypedActionDef(name = "numass.merge", inputType = Table.class, outputType = Table.class, info = "Merge different numass data files into one.")
@NodeDef(name = "grouping", info = "The defenition of grouping rule for this merge", target = "method::hep.dataforge.actions.GroupBuilder.byMeta") @NodeDef(name = "grouping", info = "The definition of grouping rule for this merge", target = "method::hep.dataforge.actions.GroupBuilder.byMeta")
public class MergeDataAction extends ManyToOneAction<Table, Table> { public class MergeDataAction extends ManyToOneAction<Table, Table> {
public static final String MERGE_NAME = "mergeName"; public static final String MERGE_NAME = "mergeName";

View File

@ -7,6 +7,7 @@ import hep.dataforge.description.TypedActionDef;
import hep.dataforge.description.ValueDef; import hep.dataforge.description.ValueDef;
import hep.dataforge.meta.Laminate; import hep.dataforge.meta.Laminate;
import hep.dataforge.meta.Meta; import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaUtils;
import hep.dataforge.names.Named; import hep.dataforge.names.Named;
import hep.dataforge.tables.ColumnFormat; import hep.dataforge.tables.ColumnFormat;
import hep.dataforge.tables.ColumnTable; import hep.dataforge.tables.ColumnTable;
@ -14,11 +15,10 @@ import hep.dataforge.tables.ListColumn;
import hep.dataforge.tables.Table; import hep.dataforge.tables.Table;
import hep.dataforge.values.Values; import hep.dataforge.values.Values;
import inr.numass.utils.NumassUtils; import inr.numass.utils.NumassUtils;
import javafx.util.Pair;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import static hep.dataforge.values.ValueType.NUMBER; import static hep.dataforge.values.ValueType.NUMBER;
import static hep.dataforge.values.ValueType.STRING; import static hep.dataforge.values.ValueType.STRING;
@ -36,15 +36,18 @@ import static inr.numass.utils.NumassUtils.pointExpression;
@ValueDef(name = "utransform", info = "Expression for voltage transformation. Uses U as input") @ValueDef(name = "utransform", info = "Expression for voltage transformation. Uses U as input")
@NodeDef(name = "correction", multiple = true, target = "method::inr.numass.actions.TransformDataAction.makeCorrection") @NodeDef(name = "correction", multiple = true, target = "method::inr.numass.actions.TransformDataAction.makeCorrection")
public class TransformDataAction extends OneToOneAction<Table, Table> { public class TransformDataAction extends OneToOneAction<Table, Table> {
@Override @Override
protected Table execute(Context context, String name, Table input, Laminate meta) { protected Table execute(Context context, String name, Table input, Laminate meta) {
List<Correction> corrections = new ArrayList<>(); List<Correction> corrections = new ArrayList<>();
if (meta.optMeta("correction").isPresent()) {
corrections.addAll(meta.getMetaList("correction").stream() meta.optMeta("corrections").ifPresent(corrs ->
.map((Function<Meta, Correction>) this::makeCorrection) MetaUtils.nodeStream(corrs)
.collect(Collectors.toList())); .map(Pair::getValue)
} .map(this::makeCorrection)
.forEach(corrections::add)
);
if (meta.hasValue("correction")) { if (meta.hasValue("correction")) {
final String correction = meta.getString("correction"); final String correction = meta.getString("correction");
@ -112,7 +115,7 @@ public class TransformDataAction extends OneToOneAction<Table, Table> {
return new Correction() { return new Correction() {
@Override @Override
public String getName() { public String getName() {
return corrMeta.getString("name", ""); return corrMeta.getString("name", corrMeta.getName());
} }
@Override @Override

View File

@ -287,7 +287,7 @@ public class LossCalculator {
* @return * @return
*/ */
public List<Double> getLossProbabilities(double X) { public List<Double> getLossProbabilities(double X) {
return lossProbCache.computeIfAbsent(X, (x) -> { return lossProbCache.computeIfAbsent(X, x -> {
List<Double> res = new ArrayList<>(); List<Double> res = new ArrayList<>();
double prob; double prob;
if (x > 0) { if (x > 0) {

View File

@ -29,9 +29,12 @@ public class NumassTransmission extends AbstractParametricBiFunction {
private final LossCalculator calculator; private final LossCalculator calculator;
private final BivariateFunction trapFunc; private final BivariateFunction trapFunc;
private final boolean adjustX;
public NumassTransmission(Context context, Meta meta) { public NumassTransmission(Context context, Meta meta) {
super(list); super(list);
this.calculator = LossCalculator.instance(); this.calculator = LossCalculator.instance();
adjustX = meta.getBoolean("adjustX",false);
if (meta.hasValue("trapping")) { if (meta.hasValue("trapping")) {
String trapFuncStr = meta.getString("trapping"); String trapFuncStr = meta.getString("trapping");
if (trapFuncStr.startsWith("function::")) { if (trapFuncStr.startsWith("function::")) {
@ -50,12 +53,16 @@ public class NumassTransmission extends AbstractParametricBiFunction {
} }
} }
public static double getX(double eIn, Values set) { public double getX(double eIn, Values set) {
if(adjustX){
//From our article //From our article
return set.getDouble("X") * Math.log(eIn / ION_POTENTIAL) * eIn * ION_POTENTIAL / 1.9580741410115568e6; return set.getDouble("X") * Math.log(eIn / ION_POTENTIAL) * eIn * ION_POTENTIAL / 1.9580741410115568e6;
} else {
return set.getDouble("X");
}
} }
public static double p0(double eIn, Values set) { public double p0(double eIn, Values set) {
return LossCalculator.instance().getLossProbability(0, getX(eIn, set)); return LossCalculator.instance().getLossProbability(0, getX(eIn, set));
} }

View File

@ -45,7 +45,7 @@ public class SterileNeutrinoSpectrum extends AbstractParametricFunction {
/** /**
* variables:Ein,Eout; parameters: "A" * variables:Ein,Eout; parameters: "A"
*/ */
private final ParametricBiFunction transmission; private final NumassTransmission transmission;
/** /**
* variables:Eout,U; parameters: "X", "trap" * variables:Eout,U; parameters: "X", "trap"
*/ */
@ -193,7 +193,7 @@ public class SterileNeutrinoSpectrum extends AbstractParametricFunction {
@Override @Override
public double value(double eIn, double u, Values set) { public double value(double eIn, double u, Values set) {
double p0 = NumassTransmission.p0(eIn, set); double p0 = transmission.p0(eIn, set);
return p0 * resolution.value(eIn, u, set) + lossRes(transmission, eIn, u, set); return p0 * resolution.value(eIn, u, set) + lossRes(transmission, eIn, u, set);
} }

View File

@ -38,7 +38,7 @@ public class NumassTableFilterTask extends SingleActionTask<Table, Table> {
protected TaskModel transformModel(TaskModel model) { protected TaskModel transformModel(TaskModel model) {
MetaBuilder metaBuilder = new MetaBuilder(model.meta()).removeNode("filter"); MetaBuilder metaBuilder = new MetaBuilder(model.meta()).removeNode("filter");
if (model.meta().hasMeta("empty")) { if (model.meta().hasMeta("empty")) {
model.dependsOn("substractEmpty", metaBuilder.build(), "prepare"); model.dependsOn("subtractEmpty", metaBuilder.build(), "prepare");
} else { } else {
model.dependsOn("prepare", metaBuilder.build(), "prepare"); model.dependsOn("prepare", metaBuilder.build(), "prepare");
} }

View File

@ -17,6 +17,7 @@ import hep.dataforge.storage.commons.JSONMetaWriter
import hep.dataforge.tables.Table import hep.dataforge.tables.Table
import hep.dataforge.tables.ValueMap import hep.dataforge.tables.ValueMap
import hep.dataforge.tables.XYAdapter import hep.dataforge.tables.XYAdapter
import inr.numass.data.NumassDataUtils
import inr.numass.data.analyzers.SimpleAnalyzer import inr.numass.data.analyzers.SimpleAnalyzer
import inr.numass.data.api.NumassAnalyzer import inr.numass.data.api.NumassAnalyzer
import inr.numass.data.api.NumassPoint import inr.numass.data.api.NumassPoint
@ -324,7 +325,7 @@ class NumassLoaderView : View() {
PlottableData.plot( PlottableData.plot(
seriesName, seriesName,
XYAdapter(NumassAnalyzer.CHANNEL_KEY, valueAxis), XYAdapter(NumassAnalyzer.CHANNEL_KEY, valueAxis),
NumassAnalyzer.spectrumWithBinning(getSpectrum(point), binning) NumassDataUtils.spectrumWithBinning(getSpectrum(point), binning)
).apply { ).apply {
configure(plottableConfig) configure(plottableConfig)
}.also { }.also {