minor refactoring
This commit is contained in:
parent
d9e5ff90ec
commit
cd16a2bb6f
@ -1,5 +1,6 @@
|
|||||||
package inr.numass
|
package inr.numass
|
||||||
|
|
||||||
|
import hep.dataforge.context.GlobalContext
|
||||||
import hep.dataforge.grind.GrindShell
|
import hep.dataforge.grind.GrindShell
|
||||||
import hep.dataforge.grind.GrindWorkspaceBuilder
|
import hep.dataforge.grind.GrindWorkspaceBuilder
|
||||||
|
|
||||||
@ -14,10 +15,15 @@ println cli.usage
|
|||||||
|
|
||||||
String cfgPath = cli.parse(args).c;
|
String cfgPath = cli.parse(args).c;
|
||||||
println "Loading config file from $cfgPath"
|
println "Loading config file from $cfgPath"
|
||||||
|
try {
|
||||||
new GrindShell().launch {
|
new GrindShell().launch {
|
||||||
context.pluginManager().loadPlugin("plots-jfc")
|
|
||||||
GrindWorkspaceBuilder numass = new GrindWorkspaceBuilder()
|
GrindWorkspaceBuilder numass = new GrindWorkspaceBuilder()
|
||||||
.withSpec(NumassWorkspaceSpec)
|
.withSpec(NumassWorkspaceSpec)
|
||||||
.from(new File(cfgPath))
|
.from(new File(cfgPath))
|
||||||
bind("numass", numass)
|
bind("numass", numass)
|
||||||
}
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
GlobalContext.instance().close();
|
||||||
|
}
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
@ -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 = "lowerWindowSlope", type = "NUMBER", def = "0", info = "Slope for the window lowerWindow bound")
|
||||||
@ValueDef(name = "upperWindow", type = "NUMBER", info = "Upper bound for window")
|
@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 = "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",
|
@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 class PrepareDataAction extends OneToOneAction<NumassData, Table> {
|
||||||
|
|
||||||
public static String[] parnames = {"Uset", "Uread", "Length", "Total", "Window", "Corr", "CR", "CRerr", "Timestamp"};
|
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;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getResultName(String dataName, Meta actionMeta) {
|
||||||
|
return super.getResultName(dataName, actionMeta);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The factor to correct for count below detector threshold
|
* The factor to correct for count below detector threshold
|
||||||
*
|
*
|
||||||
|
@ -36,9 +36,7 @@ public class SubstractSpectrumAction extends OneToOneAction<Table, Table> {
|
|||||||
input.stream().forEach(point -> {
|
input.stream().forEach(point -> {
|
||||||
MapPoint.Builder pointBuilder = new MapPoint.Builder(point);
|
MapPoint.Builder pointBuilder = new MapPoint.Builder(point);
|
||||||
Optional<DataPoint> referencePoint = referenceTable.stream()
|
Optional<DataPoint> referencePoint = referenceTable.stream()
|
||||||
.filter(p -> {
|
.filter(p -> Math.abs(p.getDouble("Uset") - point.getDouble("Uset")) < 0.1).findFirst();
|
||||||
return Math.abs(p.getDouble("Uset") - point.getDouble("Uset")) < 0.1;
|
|
||||||
}).findFirst();
|
|
||||||
if (referencePoint.isPresent()) {
|
if (referencePoint.isPresent()) {
|
||||||
pointBuilder.putValue("CR", Math.max(0, point.getDouble("CR") - referencePoint.get().getDouble("CR")));
|
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)));
|
pointBuilder.putValue("CRerr", Math.sqrt(Math.pow(point.getDouble("CRerr"), 2d) + Math.pow(referencePoint.get().getDouble("CRerr"), 2d)));
|
||||||
|
@ -17,35 +17,39 @@ package inr.numass.storage;
|
|||||||
|
|
||||||
import hep.dataforge.tables.DataPoint;
|
import hep.dataforge.tables.DataPoint;
|
||||||
import hep.dataforge.tables.MapPoint;
|
import hep.dataforge.tables.MapPoint;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
import static java.util.Arrays.sort;
|
import static java.util.Arrays.sort;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Darksnake
|
* @author Darksnake
|
||||||
*/
|
*/
|
||||||
public class NMPoint {
|
public class NMPoint {
|
||||||
|
//TODO transform to annotated and move some parameters to meta
|
||||||
static final String[] dataNames = {"chanel", "count"};
|
static final String[] dataNames = {"chanel", "count"};
|
||||||
private Instant startTime;
|
private Instant startTime;
|
||||||
|
|
||||||
// private MonitorCorrector corrector = null;
|
|
||||||
// private double deadTime;
|
|
||||||
private long eventsCount;
|
private long eventsCount;
|
||||||
|
|
||||||
private int overflow;
|
private int overflow;
|
||||||
|
|
||||||
private double pointLength;
|
private double pointLength;
|
||||||
// private final MeasurementPoint point;
|
|
||||||
private final int[] spectrum;
|
private final int[] spectrum;
|
||||||
private double uread;
|
private double uread;
|
||||||
private double uset;
|
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) {
|
public NMPoint(RawNMPoint point) {
|
||||||
if (point == null) {
|
if (point == null) {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
@ -56,14 +60,9 @@ public class NMPoint {
|
|||||||
this.uread = point.getUread();
|
this.uread = point.getUread();
|
||||||
this.startTime = point.getStartTime();
|
this.startTime = point.getStartTime();
|
||||||
this.eventsCount = point.getEventsCount();
|
this.eventsCount = point.getEventsCount();
|
||||||
// this.point = point;
|
|
||||||
spectrum = calculateSpectrum(point);
|
spectrum = calculateSpectrum(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public PointSpectrum(RawPoint point, double deadTime) {
|
|
||||||
// this(point);
|
|
||||||
// this.deadTime = deadTime;
|
|
||||||
// }
|
|
||||||
private int[] calculateSpectrum(RawNMPoint point) {
|
private int[] calculateSpectrum(RawNMPoint point) {
|
||||||
assert point.getEventsCount() > 0;
|
assert point.getEventsCount() > 0;
|
||||||
|
|
||||||
@ -238,4 +237,7 @@ public class NMPoint {
|
|||||||
return uset;
|
return uset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int[] getSpectrum() {
|
||||||
|
return spectrum;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user