minor refactoring

This commit is contained in:
Alexander Nozik 2016-11-04 11:32:00 +03:00
parent d9e5ff90ec
commit cd16a2bb6f
5 changed files with 78 additions and 33 deletions

View File

@ -1,5 +1,6 @@
package inr.numass
import hep.dataforge.context.GlobalContext
import hep.dataforge.grind.GrindShell
import hep.dataforge.grind.GrindWorkspaceBuilder
@ -14,10 +15,15 @@ println cli.usage
String cfgPath = cli.parse(args).c;
println "Loading config file from $cfgPath"
new GrindShell().launch {
context.pluginManager().loadPlugin("plots-jfc")
GrindWorkspaceBuilder numass = new GrindWorkspaceBuilder()
.withSpec(NumassWorkspaceSpec)
.from(new File(cfgPath))
bind("numass", numass)
try {
new GrindShell().launch {
GrindWorkspaceBuilder numass = new GrindWorkspaceBuilder()
.withSpec(NumassWorkspaceSpec)
.from(new File(cfgPath))
bind("numass", numass)
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
GlobalContext.instance().close();
}

View File

@ -0,0 +1,40 @@
package inr.numass.actions;
import hep.dataforge.actions.ManyToOneAction;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.meta.Meta;
import inr.numass.storage.NMPoint;
import inr.numass.storage.NumassData;
import java.util.Collection;
import java.util.Map;
import java.util.stream.IntStream;
/**
* Created by darksnake on 04-Nov-16.
*/
@TypedActionDef(name = "joinData", inputType = NumassData.class, outputType = NumassData.class,
info = "Join a number of numass data files into one single file via spectrum summing")
public class JoinNumassDataAction extends ManyToOneAction<NumassData, NumassData> {
@Override
protected NumassData execute(String nodeName, Map<String, NumassData> input, Meta meta) {
throw new UnsupportedOperationException("not implemented");
}
private NMPoint joinPoint(Collection<NMPoint> points) {
return points.stream().reduce((p1, p2) -> {
if (p1.getUset() != p2.getUset()) {
throw new RuntimeException("Can't sum points with different Uset");
}
return new NMPoint(
p1.getUset(),
(p1.getUread() + p2.getUset()) / 2,
p1.getStartTime(),
p1.getLength() + p2.getLength(),
p1.getOverflow() + p2.getOverflow(),
IntStream.range(0, p1.getSpectrum().length).map(i -> p1.getSpectrum()[i] * p2.getSpectrum()[i]).toArray()
);
}).get();
}
}

View File

@ -48,14 +48,8 @@ import static inr.numass.utils.TritiumUtils.evaluateExpression;
@ValueDef(name = "lowerWindowSlope", type = "NUMBER", def = "0", info = "Slope for the window lowerWindow bound")
@ValueDef(name = "upperWindow", type = "NUMBER", info = "Upper bound for window")
@ValueDef(name = "deadTime", type = "[NUMBER, STRING]", def = "0", info = "Dead time in s. Could be an expression.")
//@ValueDef(name = "underflow", type = "BOOLEAN", def = "true",
// info = "Enables calculation of detector threshold underflow using exponential shape of energy spectrum tail. "
// + "Not recomended to use with floating window.")
//@ValueDef(name = "underflow.upperBorder", type = "NUMBER", def = "800", info = "Upper chanel for underflow calculation.")
//@ValueDef(name = "underflow.threshold", type = "NUMBER", def = "17000", info = "The maximum U for undeflow calculation")
//@ValueDef(name = "underflow.function", info = "An expression for underflow correction above threshold")
@ValueDef(name = "correction",
info = "An expression to correct count tumber depending on potential ${U}, point length ${T} and point itself as ${point}")
info = "An expression to correct count number depending on potential `U`, point length `T` and point itself as `point`")
public class PrepareDataAction extends OneToOneAction<NumassData, Table> {
public static String[] parnames = {"Uset", "Uread", "Length", "Total", "Window", "Corr", "CR", "CRerr", "Timestamp"};
@ -135,6 +129,11 @@ public class PrepareDataAction extends OneToOneAction<NumassData, Table> {
return data;
}
@Override
protected String getResultName(String dataName, Meta actionMeta) {
return super.getResultName(dataName, actionMeta);
}
/**
* The factor to correct for count below detector threshold
*

View File

@ -29,16 +29,14 @@ public class SubstractSpectrumAction extends OneToOneAction<Table, Table> {
@Override
protected Table execute(String name, Laminate inputMeta, Table input) {
try {
String referencePath = inputMeta.getString("file", "empty.dat");
String referencePath = inputMeta. getString("file", "empty.dat");
File referenceFile = getContext().io().getFile(referencePath);
Table referenceTable = new ColumnedDataReader(referenceFile).toTable();
ListTable.Builder builder = new ListTable.Builder(input.getFormat());
input.stream().forEach(point -> {
MapPoint.Builder pointBuilder = new MapPoint.Builder(point);
Optional<DataPoint> referencePoint = referenceTable.stream()
.filter(p -> {
return Math.abs(p.getDouble("Uset") - point.getDouble("Uset")) < 0.1;
}).findFirst();
.filter(p -> Math.abs(p.getDouble("Uset") - point.getDouble("Uset")) < 0.1).findFirst();
if (referencePoint.isPresent()) {
pointBuilder.putValue("CR", Math.max(0, point.getDouble("CR") - referencePoint.get().getDouble("CR")));
pointBuilder.putValue("CRerr", Math.sqrt(Math.pow(point.getDouble("CRerr"), 2d) + Math.pow(referencePoint.get().getDouble("CRerr"), 2d)));

View File

@ -17,35 +17,39 @@ package inr.numass.storage;
import hep.dataforge.tables.DataPoint;
import hep.dataforge.tables.MapPoint;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.*;
import java.util.stream.IntStream;
import static java.util.Arrays.sort;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
*
* @author Darksnake
*/
public class NMPoint {
//TODO transform to annotated and move some parameters to meta
static final String[] dataNames = {"chanel", "count"};
private Instant startTime;
// private MonitorCorrector corrector = null;
// private double deadTime;
private long eventsCount;
private int overflow;
private double pointLength;
// private final MeasurementPoint point;
private final int[] spectrum;
private double uread;
private double uset;
public NMPoint(double uset, double uread, Instant startTime, double pointLength, int overflow, int[] spectrum) {
this.startTime = startTime;
this.overflow = overflow;
this.pointLength = pointLength;
this.spectrum = spectrum;
this.uread = uread;
this.uset = uset;
this.eventsCount = IntStream.of(spectrum).sum() + overflow;
}
public NMPoint(RawNMPoint point) {
if (point == null) {
throw new IllegalArgumentException();
@ -56,14 +60,9 @@ public class NMPoint {
this.uread = point.getUread();
this.startTime = point.getStartTime();
this.eventsCount = point.getEventsCount();
// this.point = point;
spectrum = calculateSpectrum(point);
}
// public PointSpectrum(RawPoint point, double deadTime) {
// this(point);
// this.deadTime = deadTime;
// }
private int[] calculateSpectrum(RawNMPoint point) {
assert point.getEventsCount() > 0;
@ -238,4 +237,7 @@ public class NMPoint {
return uset;
}
public int[] getSpectrum() {
return spectrum;
}
}