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.
*/
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[] NAME_LIST_WITH_HV = {HV_KEY, LENGTH_KEY, COUNT_KEY, COUNT_RATE_KEY, COUNT_RATE_ERROR_KEY, "window", "timestamp"};
public static String WINDOW_KEY = "window";
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
private final SignalProcessor processor;
@ -40,17 +42,25 @@ public abstract class AbstractAnalyzer implements NumassAnalyzer {
* @return
*/
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) {
return block.getEvents();
} else if (getProcessor() == null) {
throw new IllegalArgumentException("Signal processor needed to analyze frames");
} else {
//TODO
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;
return Stream.concat(block.getEvents(), block.getFrames().flatMap(getProcessor()::analyze));
}
}
@ -63,7 +73,7 @@ public abstract class AbstractAnalyzer implements NumassAnalyzer {
.addNumber(COUNT_KEY)
.addNumber(COUNT_RATE_KEY, Y_VALUE_KEY)
.addNumber(COUNT_RATE_ERROR_KEY, Y_ERROR_KEY)
.addColumn("window")
.addColumn(WINDOW_KEY)
.addTime()
.build();

View File

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

View File

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

View File

@ -55,7 +55,7 @@ public interface NumassAnalyzer {
* @param block
* @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

View File

@ -33,6 +33,8 @@ import hep.dataforge.stat.models.XYModel;
import hep.dataforge.tables.PointAdapter;
import hep.dataforge.tables.XYAdapter;
import inr.numass.actions.*;
import inr.numass.data.api.NumassAnalyzer;
import inr.numass.data.api.NumassPoint;
import inr.numass.models.*;
import inr.numass.models.sterile.SterileNeutrinoSpectrum;
import inr.numass.tasks.*;
@ -296,7 +298,7 @@ public class NumassPlugin extends BasicPlugin {
if (an.hasMeta(PointAdapter.DATA_ADAPTER_KEY)) {
return new XYAdapter(an.getMeta(PointAdapter.DATA_ADAPTER_KEY));
} 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
*/
@TypedActionDef(name = "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")
@TypedActionDef(name = "numass.merge", inputType = Table.class, outputType = Table.class, info = "Merge different numass data files into one.")
@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 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.meta.Laminate;
import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaUtils;
import hep.dataforge.names.Named;
import hep.dataforge.tables.ColumnFormat;
import hep.dataforge.tables.ColumnTable;
@ -14,11 +15,10 @@ import hep.dataforge.tables.ListColumn;
import hep.dataforge.tables.Table;
import hep.dataforge.values.Values;
import inr.numass.utils.NumassUtils;
import javafx.util.Pair;
import java.util.ArrayList;
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.STRING;
@ -36,15 +36,18 @@ import static inr.numass.utils.NumassUtils.pointExpression;
@ValueDef(name = "utransform", info = "Expression for voltage transformation. Uses U as input")
@NodeDef(name = "correction", multiple = true, target = "method::inr.numass.actions.TransformDataAction.makeCorrection")
public class TransformDataAction extends OneToOneAction<Table, Table> {
@Override
protected Table execute(Context context, String name, Table input, Laminate meta) {
List<Correction> corrections = new ArrayList<>();
if (meta.optMeta("correction").isPresent()) {
corrections.addAll(meta.getMetaList("correction").stream()
.map((Function<Meta, Correction>) this::makeCorrection)
.collect(Collectors.toList()));
}
meta.optMeta("corrections").ifPresent(corrs ->
MetaUtils.nodeStream(corrs)
.map(Pair::getValue)
.map(this::makeCorrection)
.forEach(corrections::add)
);
if (meta.hasValue("correction")) {
final String correction = meta.getString("correction");
@ -112,7 +115,7 @@ public class TransformDataAction extends OneToOneAction<Table, Table> {
return new Correction() {
@Override
public String getName() {
return corrMeta.getString("name", "");
return corrMeta.getString("name", corrMeta.getName());
}
@Override

View File

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

View File

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

View File

@ -45,7 +45,7 @@ public class SterileNeutrinoSpectrum extends AbstractParametricFunction {
/**
* variables:Ein,Eout; parameters: "A"
*/
private final ParametricBiFunction transmission;
private final NumassTransmission transmission;
/**
* variables:Eout,U; parameters: "X", "trap"
*/
@ -193,7 +193,7 @@ public class SterileNeutrinoSpectrum extends AbstractParametricFunction {
@Override
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);
}

View File

@ -38,7 +38,7 @@ public class NumassTableFilterTask extends SingleActionTask<Table, Table> {
protected TaskModel transformModel(TaskModel model) {
MetaBuilder metaBuilder = new MetaBuilder(model.meta()).removeNode("filter");
if (model.meta().hasMeta("empty")) {
model.dependsOn("substractEmpty", metaBuilder.build(), "prepare");
model.dependsOn("subtractEmpty", metaBuilder.build(), "prepare");
} else {
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.ValueMap
import hep.dataforge.tables.XYAdapter
import inr.numass.data.NumassDataUtils
import inr.numass.data.analyzers.SimpleAnalyzer
import inr.numass.data.api.NumassAnalyzer
import inr.numass.data.api.NumassPoint
@ -324,7 +325,7 @@ class NumassLoaderView : View() {
PlottableData.plot(
seriesName,
XYAdapter(NumassAnalyzer.CHANNEL_KEY, valueAxis),
NumassAnalyzer.spectrumWithBinning(getSpectrum(point), binning)
NumassDataUtils.spectrumWithBinning(getSpectrum(point), binning)
).apply {
configure(plottableConfig)
}.also {