diff --git a/numass-main/src/main/groovy/inr/numass/LaunchGrindShell.groovy b/numass-main/src/main/groovy/inr/numass/LaunchGrindShell.groovy index 46aeedb0..b09c041f 100644 --- a/numass-main/src/main/groovy/inr/numass/LaunchGrindShell.groovy +++ b/numass-main/src/main/groovy/inr/numass/LaunchGrindShell.groovy @@ -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(); } \ No newline at end of file diff --git a/numass-main/src/main/java/inr/numass/actions/JoinNumassDataAction.java b/numass-main/src/main/java/inr/numass/actions/JoinNumassDataAction.java new file mode 100644 index 00000000..8ebc5c53 --- /dev/null +++ b/numass-main/src/main/java/inr/numass/actions/JoinNumassDataAction.java @@ -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 { + + @Override + protected NumassData execute(String nodeName, Map input, Meta meta) { + throw new UnsupportedOperationException("not implemented"); + } + + private NMPoint joinPoint(Collection 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(); + } +} diff --git a/numass-main/src/main/java/inr/numass/actions/PrepareDataAction.java b/numass-main/src/main/java/inr/numass/actions/PrepareDataAction.java index 6357550b..140e3a43 100644 --- a/numass-main/src/main/java/inr/numass/actions/PrepareDataAction.java +++ b/numass-main/src/main/java/inr/numass/actions/PrepareDataAction.java @@ -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 { public static String[] parnames = {"Uset", "Uread", "Length", "Total", "Window", "Corr", "CR", "CRerr", "Timestamp"}; @@ -135,6 +129,11 @@ public class PrepareDataAction extends OneToOneAction { return data; } + @Override + protected String getResultName(String dataName, Meta actionMeta) { + return super.getResultName(dataName, actionMeta); + } + /** * The factor to correct for count below detector threshold * diff --git a/numass-main/src/main/java/inr/numass/actions/SubstractSpectrumAction.java b/numass-main/src/main/java/inr/numass/actions/SubstractSpectrumAction.java index ca632c10..f42d859d 100644 --- a/numass-main/src/main/java/inr/numass/actions/SubstractSpectrumAction.java +++ b/numass-main/src/main/java/inr/numass/actions/SubstractSpectrumAction.java @@ -29,16 +29,14 @@ public class SubstractSpectrumAction extends OneToOneAction { @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 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))); diff --git a/numass-storage/src/main/java/inr/numass/storage/NMPoint.java b/numass-storage/src/main/java/inr/numass/storage/NMPoint.java index fad39faa..519ee60c 100644 --- a/numass-storage/src/main/java/inr/numass/storage/NMPoint.java +++ b/numass-storage/src/main/java/inr/numass/storage/NMPoint.java @@ -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; + } }