This commit is contained in:
darksnake 2017-04-13 17:06:41 +03:00
parent 170b537a57
commit 30c912bd3a
24 changed files with 307 additions and 260 deletions

View File

@ -1,9 +1,10 @@
apply plugin: 'groovy'
apply plugin: 'application'
//if (!hasProperty('mainClass')) {
// ext.mainClass = 'inr.numass.LaunchGrindShell'
//}
//mainClassName = mainClass
mainClassName = 'inr.numass.LaunchGrindShell'
description = "Main numass project"

View File

@ -13,7 +13,7 @@ import hep.dataforge.tables.TableFormatBuilder
import inr.numass.storage.NumassData
NumassData.metaClass.findPoint{double u ->
delegate.getNMPoints().getWork{it.getUset() == u}.getMapWithBinning(20,true)
delegate.getNMPoints().getWork { it.getVoltage() == u }.getMap(20, true)
}
Map<Double, Double> dif(NumassData data1, NumassData data2, double uset){

View File

@ -74,7 +74,7 @@ PileUpSimulator buildSimulator(NMPoint point, double cr, NMPoint reference = nul
if (i < lowerChannel) {
values[i] = point.getLength()*amp * Math.exp((i as double) / sigma)
} else {
values[i] = Math.max(0, point.getCountInChanel(i) - (reference == null ? 0 : reference.getCountInChanel(i)));
values[i] = Math.max(0, point.getCount(i) - (reference == null ? 0 : reference.getCount(i)));
}
}
generator.loadSpectrum(chanels, values)
@ -85,7 +85,7 @@ PileUpSimulator buildSimulator(NMPoint point, double cr, NMPoint reference = nul
generator.loadSpectrum(point, reference, lowerChannel, upperChannel);
}
return new PileUpSimulator(point.length * scale, rnd, generator).withUset(point.uset).generate();
return new PileUpSimulator(point.length * scale, rnd, generator).withUset(point.voltage).generate();
}
double adjustCountRate(PileUpSimulator simulator, NMPoint point) {
@ -129,7 +129,7 @@ def keys = res.keySet();
//print spectra for selected point
double u = 16500d;
List<Map> points = res.values().collect { it.find { it.uset == u }.getMapWithBinning(20, true) }
List<Map> points = res.values().collect { it.find { it.voltage == u }.getMap(20, true) }
println "\n Spectrum example for U = ${u}\n"
@ -148,9 +148,9 @@ print keys.collect { it + "[pulse]" }.join("\t") + "\t"
println keys.join("\t")
for (int i = 0; i < data.size(); i++) {
print "${data.get(i).getUset()}\t"
print "${data.get(i).getVoltage()}\t"
print "${data.get(i).getLength()}\t"
print keys.collect { res[it].get(i).getEventsCount() }.join("\t") + "\t"
print keys.collect { res[it].get(i).getTotalCount() }.join("\t") + "\t"
print keys.collect { res[it].get(i).getCountInWindow(3100, 3800) }.join("\t") + "\t"
println keys.collect { res[it].get(i).getCountInWindow(400, 3100) }.join("\t")
}

View File

@ -42,26 +42,26 @@ data = NumassDataUtils.substractReferencePoint(data, 18600d);
//emptySpectra = NumassDataUtils.substractReferencePoint(emptySpectra,18600);
//
//data = data.collect { point ->
// NMPoint ref = emptySpectra.find { it.uset == point.uset }
// NMPoint ref = emptySpectra.find { it.u == point.u }
// if (ref) {
// println "substracting tritium background for point ${point.uset}"
// println "substracting tritium background for point ${point.u}"
// NumassDataUtils.substractPoint(point, ref)
// } else {
// println "point ${point.uset} skipped"
// println "point ${point.u} skipped"
// point
// }
//}
def printPoint(Iterable<NMPoint> data, List us, int binning = 20, normalize = true) {
List<NMPoint> points = data.findAll { it.uset in us }.sort { it.uset }
List<NMPoint> points = data.findAll { it.voltage in us }.sort { it.voltage }
Map spectra = points.first().getMapWithBinning(binning, normalize).collectEntries { key, value ->
Map spectra = points.first().getMap(binning, normalize).collectEntries { key, value ->
[key, [value]]
};
points.eachWithIndex { it, index ->
print "\t${it.uset}"
it.getMapWithBinning(binning, normalize).each { k, v ->
print "\t${it.voltage}"
it.getMap(binning, normalize).each { k, v ->
spectra[k].add(v)
}
}

View File

@ -26,13 +26,14 @@ import hep.dataforge.tables.MapPoint;
import hep.dataforge.tables.Table;
import hep.dataforge.values.Value;
import inr.numass.storage.NMFile;
import inr.numass.storage.NMPoint;
import inr.numass.storage.NumassData;
import inr.numass.storage.NumassPoint;
import org.apache.commons.math3.analysis.UnivariateFunction;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author Darksnake
@ -53,9 +54,9 @@ public class FindBorderAction extends OneToOneAction<NumassData, Table> {
int lowerBorder = meta.getInt("lower", 0);
double substractReference = meta.getDouble("reference", 0);
NMPoint referencePoint = null;
NumassPoint referencePoint = null;
if (substractReference > 0) {
referencePoint = source.getByUset(substractReference);
referencePoint = source.getByVoltage(substractReference);
if (referencePoint == null) {
report(context, name, "Reference point {} not found", substractReference);
}
@ -85,21 +86,26 @@ public class FindBorderAction extends OneToOneAction<NumassData, Table> {
return res;
}
private void fill(ListTable.Builder dataBuilder, NumassData file, int lower, int upper, NMPoint reference) {
for (NMPoint point : file) {
if ((reference != null) && (point.getUset() == reference.getUset())) {
private void fill(ListTable.Builder dataBuilder, NumassData file, int lower, int upper, NumassPoint reference) {
for (NumassPoint point : file) {
if ((reference != null) && (point.getVoltage() == reference.getVoltage())) {
continue;
}
//создаем основу для будущей точки
HashMap<String, Value> map = new HashMap<>();
map.put(names[0], Value.of(point.getUset()));
map.put(names[0], Value.of(point.getVoltage()));
Map<Double, Double> spectrum;
if (reference != null) {
spectrum = point.getMapWithBinning(reference, 0);
Map<Double, Double> sp = point.getMap(0, true);
Map<Double, Double> referenceSpectrum = reference.getMap(0, true);
spectrum = sp.entrySet().stream()
.collect(Collectors.toMap(entry -> entry.getKey(), entry -> Math.max(entry.getValue() - referenceSpectrum.get(entry.getKey()), 0)));
} else {
spectrum = point.getMapWithBinning(0, true);
spectrum = point.getMap(0, true);
}
double norm = getNorm(spectrum, lower, upper) * normCorrection.value(point.getUset());
double norm = getNorm(spectrum, lower, upper) * normCorrection.value(point.getVoltage());
double counter = 0;
int chanel = upper;
while (chanel > lower) {

View File

@ -6,6 +6,7 @@ import hep.dataforge.description.TypedActionDef;
import hep.dataforge.meta.Laminate;
import inr.numass.storage.NMPoint;
import inr.numass.storage.NumassData;
import inr.numass.storage.NumassPoint;
import java.util.Collection;
import java.util.Map;
@ -23,14 +24,13 @@ public class JoinNumassDataAction extends ManyToOneAction<NumassData, NumassData
throw new UnsupportedOperationException("not implemented");
}
private NMPoint joinPoint(Collection<NMPoint> points) {
private NumassPoint joinPoint(Collection<NumassPoint> points) {
return points.stream().reduce((p1, p2) -> {
if (p1.getUset() != p2.getUset()) {
if (p1.getVoltage() != p2.getVoltage()) {
throw new RuntimeException("Can't sum points with different Uset");
}
return new NMPoint(
p1.getUset(),
(p1.getUread() + p2.getUset()) / 2,
(p1.getVoltage() + p2.getVoltage()) / 2,
p1.getStartTime(),
p1.getLength() + p2.getLength(),
IntStream.range(0, p1.getSpectrum().length).map(i -> p1.getSpectrum()[i] * p2.getSpectrum()[i]).toArray()

View File

@ -28,10 +28,7 @@ import hep.dataforge.meta.Meta;
import hep.dataforge.tables.*;
import inr.numass.debunch.DebunchReport;
import inr.numass.debunch.FrameAnalizer;
import inr.numass.storage.NMPoint;
import inr.numass.storage.NumassData;
import inr.numass.storage.NumassDataLoader;
import inr.numass.storage.RawNMPoint;
import inr.numass.storage.*;
import inr.numass.utils.ExpressionUtils;
import java.io.OutputStream;
@ -111,10 +108,10 @@ public class PrepareDataAction extends OneToOneAction<NumassData, Table> {
}
List<DataPoint> dataList = new ArrayList<>();
for (NMPoint point : dataFile) {
for (NumassPoint point : dataFile) {
long total = point.getEventsCount();
double uset = utransform.apply(point.getUset());
long total = point.getTotalCount();
double uset = utransform.apply(point.getVoltage());
double uread = utransform.apply(point.getUread());
double time = point.getLength();
int a = getLowerBorder(meta, uset);
@ -179,12 +176,12 @@ public class PrepareDataAction extends OneToOneAction<NumassData, Table> {
final String errExpr = corrMeta.getString("err", "");
return new Correction() {
@Override
public double corr(NMPoint point) {
public double corr(NumassPoint point) {
return pointExpression(expr, point);
}
@Override
public double corrErr(NMPoint point) {
public double corrErr(NumassPoint point) {
if (errExpr.isEmpty()) {
return 0;
} else {
@ -194,7 +191,7 @@ public class PrepareDataAction extends OneToOneAction<NumassData, Table> {
};
}
private NMPoint debunch(Context context, RawNMPoint point, Meta meta) {
private NumassPoint debunch(Context context, RawNMPoint point, Meta meta) {
int upper = meta.getInt("upperchanel", RawNMPoint.MAX_CHANEL);
int lower = meta.getInt("lowerchanel", 0);
double rejectionprob = meta.getDouble("rejectprob", 1e-10);
@ -218,7 +215,7 @@ public class PrepareDataAction extends OneToOneAction<NumassData, Table> {
* @param point
* @return
*/
double corr(NMPoint point);
double corr(NumassPoint point);
/**
* correction coefficient uncertainty
@ -226,11 +223,11 @@ public class PrepareDataAction extends OneToOneAction<NumassData, Table> {
* @param point
* @return
*/
default double corrErr(NMPoint point) {
default double corrErr(NumassPoint point) {
return 0;
}
default double relativeErr(NMPoint point) {
default double relativeErr(NumassPoint point) {
double corrErr = corrErr(point);
if (corrErr == 0) {
return 0;
@ -242,18 +239,18 @@ public class PrepareDataAction extends OneToOneAction<NumassData, Table> {
private class DeadTimeCorrection implements Correction {
private final Function<NMPoint, Double> deadTimeFunction;
private final Function<NumassPoint, Double> deadTimeFunction;
public DeadTimeCorrection(String expr) {
deadTimeFunction = point -> pointExpression(expr, point);
}
@Override
public double corr(NMPoint point) {
public double corr(NumassPoint point) {
double deadTime = deadTimeFunction.apply(point);
if (deadTime > 0) {
double factor = deadTime / point.getLength() * point.getEventsCount();
// double total = point.getEventsCount();
double factor = deadTime / point.getLength() * point.getTotalCount();
// double total = point.getTotalCount();
// double time = point.getLength();
// return 1d/(1d - factor);

View File

@ -18,8 +18,8 @@ import hep.dataforge.plots.data.PlottableData;
import hep.dataforge.plots.data.XYPlottable;
import hep.dataforge.tables.*;
import hep.dataforge.values.ValueType;
import inr.numass.storage.NMPoint;
import inr.numass.storage.NumassData;
import inr.numass.storage.NumassPoint;
import java.io.OutputStream;
import java.util.*;
@ -36,7 +36,7 @@ public class ShowEnergySpectrumAction extends OneToOneAction<NumassData, Table>
protected Table execute(Context context, String name, NumassData input, Laminate inputMeta) {
int binning = inputMeta.getInt("binning", 20);
boolean normalize = inputMeta.getBoolean("normalize", true);
List<NMPoint> points = input.getNMPoints();
List<NumassPoint> points = input.getNMPoints();
if (points.isEmpty()) {
getLogger(inputMeta).error("Empty data");
@ -46,13 +46,13 @@ public class ShowEnergySpectrumAction extends OneToOneAction<NumassData, Table>
//build header
List<String> names = new ArrayList<>();
for (int i = 0; i < points.size(); i++) {
names.add(String.format("%d: %.2f", i, points.get(i).getUset()));
names.add(String.format("%d: %.2f", i, points.get(i).getVoltage()));
}
LinkedHashMap<String, Map<Double, Double>> valueMap = points.stream()
.collect(Collectors.toMap(
p -> names.get(points.indexOf(p)),
p -> p.getMapWithBinning(binning, normalize),
p -> p.getMap(binning, normalize),
(v1, v2) -> v1,
() -> new LinkedHashMap<>()
));

View File

@ -20,7 +20,7 @@ import hep.dataforge.tables.SimplePointSource;
import hep.dataforge.tables.TableFormat;
import hep.dataforge.values.Value;
import inr.numass.storage.NMFile;
import inr.numass.storage.NMPoint;
import inr.numass.storage.NumassPoint;
import org.apache.commons.math3.util.Pair;
import java.util.ArrayList;
@ -50,13 +50,13 @@ public class SlicedData extends SimplePointSource {
}
private void fill(NMFile file, Map<String,Pair<Integer,Integer>> intervals, boolean normalize){
for (NMPoint point : file) {
for (NumassPoint point : file) {
//создаем основу для будущей точки
HashMap<String,Value> map = new HashMap<>();
//Кладем напряжение
map.put(UNAME, Value.of(point.getUset()));
map.put(UNAME, Value.of(point.getVoltage()));
double t = point.getLength();
map.put(TNAME, Value.of(t));
@ -73,7 +73,7 @@ public class SlicedData extends SimplePointSource {
} else if(b<a) {
count = point.getCountInWindow(b, a);
} else{
count = point.getCountInChanel(a);
count = point.getCount(a);
}
//пихаем все в map
if(normalize){

View File

@ -15,7 +15,6 @@
*/
package inr.numass.data;
import inr.numass.storage.NMPoint;
import hep.dataforge.io.ColumnedDataWriter;
import hep.dataforge.tables.MapPoint;
import hep.dataforge.tables.SimplePointSource;
@ -23,8 +22,9 @@ import hep.dataforge.tables.TableFormat;
import hep.dataforge.tables.TableFormatBuilder;
import hep.dataforge.values.Value;
import hep.dataforge.values.ValueType;
import inr.numass.storage.NumassPoint;
import java.io.OutputStream;
import static java.lang.String.format;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -37,8 +37,15 @@ import java.util.Map;
public class ESpectrum extends SimplePointSource {
private final static String binCenter = "chanel";
int binning = 1;
private static TableFormat prepareFormat(List<NMPoint> points) {
public ESpectrum(List<NumassPoint> points, int binning, boolean normalize) {
super(prepareFormat(points));
this.binning = binning;
fill(points, normalize);
}
private static TableFormat prepareFormat(List<NumassPoint> points) {
TableFormatBuilder builder = new TableFormatBuilder();
builder.addString(binCenter);
@ -49,21 +56,13 @@ public class ESpectrum extends SimplePointSource {
return builder.build();
}
int binning = 1;
public ESpectrum(List<NMPoint> points, int binning, boolean normalize) {
super(prepareFormat(points));
this.binning = binning;
fill(points, normalize);
}
private void fill(List<NMPoint> points, boolean normalize) {
private void fill(List<NumassPoint> points, boolean normalize) {
assert !points.isEmpty();
List<Map<Double, Double>> spectra = new ArrayList<>();
for (NMPoint numassPoint : points) {
spectra.add(numassPoint.getMapWithBinning(binning, normalize));
for (NumassPoint numassPoint : points) {
spectra.add(numassPoint.getMap(binning, normalize));
}
for (Double x : spectra.get(0).keySet()) {

View File

@ -17,7 +17,7 @@ package inr.numass.utils;
import hep.dataforge.meta.Meta;
import inr.numass.storage.NMEvent;
import inr.numass.storage.NMPoint;
import inr.numass.storage.NumassPoint;
import inr.numass.storage.RawNMPoint;
import org.apache.commons.math3.distribution.EnumeratedRealDistribution;
import org.apache.commons.math3.distribution.RealDistribution;
@ -83,22 +83,22 @@ public class NMEventGenerator implements Supplier<NMEvent> {
distribution = new EnumeratedRealDistribution(channels, values);
}
public void loadSpectrum(NMPoint point) {
public void loadSpectrum(NumassPoint point) {
double[] chanels = new double[RawNMPoint.MAX_CHANEL];
double[] values = new double[RawNMPoint.MAX_CHANEL];
for (int i = 0; i < RawNMPoint.MAX_CHANEL; i++) {
chanels[i] = i;
values[i] = point.getCountInChanel(i);
values[i] = point.getCount(i);
}
distribution = new EnumeratedRealDistribution(chanels, values);
}
public void loadSpectrum(NMPoint point, NMPoint reference) {
public void loadSpectrum(NumassPoint point, NumassPoint reference) {
double[] chanels = new double[RawNMPoint.MAX_CHANEL];
double[] values = new double[RawNMPoint.MAX_CHANEL];
for (int i = 0; i < RawNMPoint.MAX_CHANEL; i++) {
chanels[i] = i;
values[i] = Math.max(0, point.getCountInChanel(i) - reference.getCountInChanel(i));
values[i] = Math.max(0, point.getCount(i) - reference.getCount(i));
}
distribution = new EnumeratedRealDistribution(chanels, values);
}
@ -109,12 +109,12 @@ public class NMEventGenerator implements Supplier<NMEvent> {
* @param lower lower channel for spectrum generation
* @param upper upper channel for spectrum generation
*/
public void loadSpectrum(NMPoint point, NMPoint reference, int lower, int upper) {
public void loadSpectrum(NumassPoint point, NumassPoint reference, int lower, int upper) {
double[] chanels = new double[RawNMPoint.MAX_CHANEL];
double[] values = new double[RawNMPoint.MAX_CHANEL];
for (int i = lower; i < upper; i++) {
chanels[i] = i;
values[i] = Math.max(0, point.getCountInChanel(i) - (reference == null ? 0 : reference.getCountInChanel(i)));
values[i] = Math.max(0, point.getCount(i) - (reference == null ? 0 : reference.getCount(i)));
}
distribution = new EnumeratedRealDistribution(chanels, values);
}

View File

@ -7,6 +7,7 @@ package inr.numass.utils;
import inr.numass.storage.NMEvent;
import inr.numass.storage.NMPoint;
import inr.numass.storage.NumassPoint;
import inr.numass.storage.RawNMPoint;
import org.apache.commons.math3.random.RandomGenerator;
@ -53,15 +54,15 @@ public class PileUpSimulator {
return this;
}
public NMPoint generated() {
public NumassPoint generated() {
return new NMPoint(new RawNMPoint(uSet, generated, pointLength));
}
public NMPoint registered() {
public NumassPoint registered() {
return new NMPoint(new RawNMPoint(uSet, registered, pointLength));
}
public NMPoint pileup() {
public NumassPoint pileup() {
return new NMPoint(new RawNMPoint(uSet, pileup, pointLength));
}

View File

@ -19,7 +19,7 @@ import hep.dataforge.tables.DataPoint;
import hep.dataforge.tables.ListTable;
import hep.dataforge.tables.Table;
import inr.numass.data.SpectrumDataAdapter;
import inr.numass.storage.NMPoint;
import inr.numass.storage.NumassPoint;
import org.apache.commons.math3.analysis.UnivariateFunction;
import java.util.HashMap;
@ -107,11 +107,11 @@ public class TritiumUtils {
return res * 1E-23;
}
public static double countRateWithDeadTime(NMPoint p, int from, int to, double deadTime) {
public static double countRateWithDeadTime(NumassPoint p, int from, int to, double deadTime) {
double wind = p.getCountInWindow(from, to) / p.getLength();
double res;
if (deadTime > 0) {
double total = p.getEventsCount();
double total = p.getTotalCount();
// double time = p.getLength();
// res = wind / (1 - total * deadTime / time);
double timeRatio = deadTime / p.getLength();
@ -122,7 +122,7 @@ public class TritiumUtils {
return res;
}
public static double countRateWithDeadTimeErr(NMPoint p, int from, int to, double deadTime) {
public static double countRateWithDeadTimeErr(NumassPoint p, int from, int to, double deadTime) {
return Math.sqrt(countRateWithDeadTime(p, from, to, deadTime) / p.getLength());
}
@ -133,11 +133,11 @@ public class TritiumUtils {
* @param point
* @return
*/
public static double pointExpression(String expression, NMPoint point) {
public static double pointExpression(String expression, NumassPoint point) {
Map<String, Object> exprParams = new HashMap<>();
exprParams.put("T", point.getLength());
exprParams.put("U", point.getUread());
exprParams.put("cr", ((double) point.getEventsCount()) / point.getLength());
exprParams.put("cr", ((double) point.getTotalCount()) / point.getLength());
exprParams.put("point", point);
return ExpressionUtils.function(expression, exprParams);
}

View File

@ -9,7 +9,7 @@ import hep.dataforge.tables.DataPoint;
import hep.dataforge.tables.ListTable;
import hep.dataforge.tables.MapPoint;
import hep.dataforge.tables.Table;
import inr.numass.storage.NMPoint;
import inr.numass.storage.NumassPoint;
import org.apache.commons.math3.analysis.ParametricUnivariateFunction;
import org.apache.commons.math3.exception.DimensionMismatchException;
import org.apache.commons.math3.fitting.SimpleCurveFitter;
@ -30,7 +30,7 @@ public class UnderflowCorrection {
// private final static int CUTOFF = -200;
// public double get(Logable log, Meta meta, NMPoint point) {
// if (point.getUset() >= meta.getDouble("underflow.threshold", 17000)) {
// if (point.getVoltage() >= meta.getDouble("underflow.threshold", 17000)) {
// if (meta.hasValue("underflow.function")) {
// return TritiumUtils.pointExpression(meta.getString("underflow.function"), point);
// } else {
@ -47,7 +47,7 @@ public class UnderflowCorrection {
// double correction = fitRes[0] * fitRes[1] * (Math.exp(xLow / fitRes[1]) - 1d) / norm + 1d;
// return correction;
// } catch (Exception ex) {
// log.reportError("Failed to calculate underflow parameters for point {} with message:", point.getUset(), ex.getMessage());
// log.reportError("Failed to calculate underflow parameters for point {} with message:", point.getVoltage(), ex.getMessage());
// return 1d;
// }
// }
@ -57,23 +57,23 @@ public class UnderflowCorrection {
// ListTable.Builder builder = new ListTable.Builder("U", "amp", "expConst");
// for (NMPoint point : data) {
// double[] fitRes = getUnderflowExpParameters(point, xLow, xHigh, binning);
// builder.row(point.getUset(), fitRes[0], fitRes[1]);
// builder.row(point.getVoltage(), fitRes[0], fitRes[1]);
// }
// return builder.build();
// }
public DataPoint fitPoint(NMPoint point, int xLow, int xHigh, int upper, int binning) {
public DataPoint fitPoint(NumassPoint point, int xLow, int xHigh, int upper, int binning) {
double norm = ((double) point.getCountInWindow(xLow, upper)) / point.getLength();
double[] fitRes = getUnderflowExpParameters(point, xLow, xHigh, binning);
double a = fitRes[0];
double sigma = fitRes[1];
return new MapPoint(pointNames,point.getUset(), a, sigma, a * sigma * Math.exp(xLow / sigma) / norm + 1d);
return new MapPoint(pointNames, point.getVoltage(), a, sigma, a * sigma * Math.exp(xLow / sigma) / norm + 1d);
}
public Table fitAllPoints(Iterable<NMPoint> data, int xLow, int xHigh, int upper, int binning) {
public Table fitAllPoints(Iterable<NumassPoint> data, int xLow, int xHigh, int upper, int binning) {
ListTable.Builder builder = new ListTable.Builder(pointNames);
for (NMPoint point : data) {
for (NumassPoint point : data) {
builder.row(fitPoint(point,xLow,xHigh,upper,binning));
}
return builder.build();
@ -88,12 +88,12 @@ public class UnderflowCorrection {
* @param xHigh
* @return
*/
private double[] getUnderflowExpParameters(NMPoint point, int xLow, int xHigh, int binning) {
private double[] getUnderflowExpParameters(NumassPoint point, int xLow, int xHigh, int binning) {
try {
if (xHigh <= xLow) {
throw new IllegalArgumentException("Wrong borders for underflow calculation");
}
List<WeightedObservedPoint> points = point.getMapWithBinning(binning, false)
List<WeightedObservedPoint> points = point.getMap(binning, false)
.entrySet().stream()
.filter(entry -> entry.getKey() >= xLow && entry.getKey() <= xHigh)
.map(p -> new WeightedObservedPoint(

View File

@ -1,4 +1,36 @@
dependencies {
compile "hep.dataforge:dataforge-storage" //project(':dataforge-storage')
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.1'
}
}
apply plugin: 'com.google.protobuf'
dependencies {
compile "hep.dataforge:dataforge-storage" //project(':dataforge-storage')
compile 'com.google.protobuf:protobuf-java:3.2.0'
}
protobuf {
// Configure the protoc executable
protoc {
// Download from repositories
artifact = 'com.google.protobuf:protoc:3.2.0'
}
generatedFilesBaseDir = "$projectDir/gen"
}
clean {
delete protobuf.generatedFilesBaseDir
}
idea {
module {
sourceDirs += file("${protobuf.generatedFilesBaseDir}/main/java");
sourceDirs += file("src/main/proto")
}
}

View File

@ -36,7 +36,7 @@ import java.util.stream.Stream;
@ValueDef(name = "numass.name", info = "The name of this data file.")
public class NMFile extends NamedMetaHolder implements NumassData {
private final List<NMPoint> points;
private final List<NumassPoint> points;
public NMFile(RawNMFile file) {
super(file.getName(), file.meta());
@ -60,7 +60,7 @@ public class NMFile extends NamedMetaHolder implements NumassData {
}
@Override
public Stream<NMPoint> stream() {
public Stream<NumassPoint> stream() {
return points.stream();
}

View File

@ -19,30 +19,27 @@ import hep.dataforge.tables.DataPoint;
import hep.dataforge.tables.MapPoint;
import java.time.Instant;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;
import static java.util.Arrays.sort;
/**
* @author Darksnake
*/
public class NMPoint {
public class NMPoint implements NumassPoint {
//TODO andThen to annotated and move some parameters to meta
static final String[] dataNames = {"chanel", "count"};
private final int[] spectrum;
private Instant startTime;
private long eventsCount;
private double pointLength;
private double uread;
private double uset;
private double u;
public NMPoint(double uset, double uread, Instant startTime, double pointLength, int[] spectrum) {
public NMPoint(double u, Instant startTime, double pointLength, int[] spectrum) {
this.startTime = startTime;
this.pointLength = pointLength;
this.spectrum = spectrum;
this.uread = uread;
this.uset = uset;
this.u = u;
this.eventsCount = IntStream.of(spectrum).sum();
}
@ -52,8 +49,8 @@ public class NMPoint {
}
this.pointLength = point.getLength();
this.uset = point.getUset();
this.uread = point.getUread();
this.u = point.getUset();
// this.uread = point.getUread();
this.startTime = point.getStartTime();
this.eventsCount = point.getEventsCount();
spectrum = calculateSpectrum(point);
@ -74,33 +71,10 @@ public class NMPoint {
return result;
}
public DataPoint fastSlice(int... borders) {
assert borders.length > 0;//FIXME replace by condition check
sort(borders);
assert borders[borders.length] < RawNMPoint.MAX_CHANEL;//FIXME replace by condition check
Integer[] slices = new Integer[borders.length + 2];
String[] names = new String[borders.length + 2];
slices[0] = getCountInWindow(0, borders[0]);
names[0] = Integer.toString(borders[0]);
for (int i = 1; i < borders.length; i++) {
slices[i] = getCountInWindow(borders[i - 1], borders[i]);
names[i] = Integer.toString(borders[i]);
}
slices[borders.length + 1] = getCountInWindow(borders[borders.length], RawNMPoint.MAX_CHANEL);
names[borders.length + 1] = Integer.toString(RawNMPoint.MAX_CHANEL);
slices[borders.length + 2] = RawNMPoint.MAX_CHANEL;
names[borders.length + 2] = "TOTAL";
//FIXME fix it!
return new MapPoint(names, slices);
}
/**
* @return the absouteTime
*/
@Override
public Instant getStartTime() {
if (startTime == null) {
return Instant.EPOCH;
@ -109,10 +83,12 @@ public class NMPoint {
}
}
public int getCountInChanel(int chanel) {
@Override
public int getCount(int chanel) {
return spectrum[chanel];
}
@Override
public int getCountInWindow(int from, int to) {
int res = 0;
for (int i = from; i <= to; i++) {
@ -124,6 +100,7 @@ public class NMPoint {
return res;
}
@Override
public List<DataPoint> getData() {
List<DataPoint> data = new ArrayList<>();
for (int i = 0; i < RawNMPoint.MAX_CHANEL; i++) {
@ -138,72 +115,11 @@ public class NMPoint {
*
* @return
*/
public long getEventsCount() {
@Override
public long getTotalCount() {
return eventsCount;
}
public List<DataPoint> getData(int binning, boolean normalize) {
List<DataPoint> data = new ArrayList<>();
double norm;
if (normalize) {
norm = getLength();
} else {
norm = 1d;
}
int i = 0;
while (i < RawNMPoint.MAX_CHANEL - binning) {
int start = i;
double sum = spectrum[start] / norm;
while (i < start + binning) {
sum += spectrum[i] / norm;
i++;
}
data.add(new MapPoint(dataNames, start + binning / 2d, sum));
}
return data;
}
public Map<Double, Double> getMapWithBinning(int binning, boolean normalize) {
Map<Double, Double> res = new LinkedHashMap<>();
double norm;
if (normalize) {
norm = getLength();
} else {
norm = 1d;
}
int i = 0;
while (i < RawNMPoint.MAX_CHANEL - binning) {
int start = i;
double sum = 0;
while (i < start + binning) {
sum += spectrum[i];
i++;
}
res.put(start + Math.floor(binning / 2d), sum / norm);
}
return res;
}
public Map<Double, Double> getMapWithBinning(NMPoint reference, int binning) {
Map<Double, Double> sp = this.getMapWithBinning(binning, true);
Map<Double, Double> referenceSpectrum = reference.getMapWithBinning(binning, true);
Map<Double, Double> res = new LinkedHashMap<>();
sp.entrySet().stream().map((entry) -> entry.getKey()).forEach((bin) -> {
res.put(bin, Math.max(sp.get(bin) - referenceSpectrum.get(bin), 0));
});
return res;
}
/**
* @return the overflow
@ -215,24 +131,20 @@ public class NMPoint {
/**
* @return the pointLength
*/
@Override
public double getLength() {
return pointLength;
}
/**
* @return the uread
* @return the u
*/
public double getUread() {
return uread;
}
/**
* @return the uset
*/
public double getUset() {
return uset;
@Override
public double getVoltage() {
return u;
}
@Override
public int[] getSpectrum() {
return spectrum;
}

View File

@ -20,21 +20,21 @@ import java.util.stream.Stream;
/**
* @author <a href="mailto:altavir@gmail.com">Alexander Nozik</a>
*/
public interface NumassData extends Named, Annotated, Iterable<NMPoint> {
public interface NumassData extends Named, Annotated, Iterable<NumassPoint> {
String getDescription();
@Override
Meta meta();
Stream<NMPoint> stream();
Stream<NumassPoint> stream();
@Override
default Iterator<NMPoint> iterator() {
default Iterator<NumassPoint> iterator() {
return stream().iterator();
}
default List<NMPoint> getNMPoints() {
default List<NumassPoint> getNMPoints() {
return stream().collect(Collectors.toList());
}
@ -52,28 +52,14 @@ public interface NumassData extends Named, Annotated, Iterable<NMPoint> {
* @param U
* @return
*/
default NMPoint getByUset(double U) {
for (NMPoint point : this) {
if (point.getUset() == U) {
default NumassPoint getByVoltage(double U) {
for (NumassPoint point : this) {
if (point.getVoltage() == U) {
return point;
}
}
return null;
}
/**
* Find first point with given Uread
*
* @param U
* @return
*/
default NMPoint getByUread(double U) {
for (NMPoint point : this) {
if (point.getUread() == U) {
return point;
}
}
return null;
}
}

View File

@ -173,7 +173,7 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
* @param transformation
* @return
*/
private NMPoint readPoint(Envelope envelope, Function<RawNMPoint, NMPoint> transformation) {
private NumassPoint readPoint(Envelope envelope, Function<RawNMPoint, NumassPoint> transformation) {
return transformation.apply(readRawPoint(envelope));
}
@ -234,7 +234,7 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
* @param envelope
* @return
*/
public NMPoint readPoint(Envelope envelope) {
public NumassPoint readPoint(Envelope envelope) {
return readPoint(envelope, NMPoint::new);
}
@ -281,11 +281,11 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
}
@Override
public Stream<NMPoint> stream() {
public Stream<NumassPoint> stream() {
return this.getPoints().map(this::readPoint);
}
public List<NMPoint> getNMPoints(Function<RawNMPoint, NMPoint> transformation) {
public List<NumassPoint> getNMPoints(Function<RawNMPoint, NumassPoint> transformation) {
return this.getPoints().map(env -> readPoint(env, transformation)).collect(Collectors.toList());
}
@ -360,7 +360,7 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
* @param transform
* @return
*/
public NumassData applyRawTransformation(Function<RawNMPoint, NMPoint> transform) {
public NumassData applyRawTransformation(Function<RawNMPoint, NumassPoint> transform) {
return new NumassData() {
@Override
public String getDescription() {
@ -373,7 +373,7 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
}
@Override
public Stream<NMPoint> stream() {
public Stream<NumassPoint> stream() {
return NumassDataLoader.this.stream();
}

View File

@ -13,11 +13,11 @@ import java.util.stream.Stream;
*/
public class NumassDataUtils {
public static Collection<NMPoint> joinSpectra(Stream<NumassData> spectra) {
Map<Double, NMPoint> map = new LinkedHashMap<>();
public static Collection<NumassPoint> joinSpectra(Stream<NumassData> spectra) {
Map<Double, NumassPoint> map = new LinkedHashMap<>();
spectra.forEach(datum -> {
datum.forEach(point -> {
double uset = point.getUset();
double uset = point.getVoltage();
if (map.containsKey(uset)) {
map.put(uset, join(point, map.get(uset)));
} else {
@ -35,35 +35,33 @@ public class NumassDataUtils {
* @param second
* @return
*/
public static NMPoint join(NMPoint first, NMPoint second) {
if (first.getUset() != second.getUset()) {
public static NumassPoint join(NumassPoint first, NumassPoint second) {
if (first.getVoltage() != second.getVoltage()) {
throw new RuntimeException("Voltage mismatch");
}
int[] newArray = new int[first.getSpectrum().length];
Arrays.setAll(newArray, i -> first.getSpectrum()[i] + second.getSpectrum()[i]);
return new NMPoint(
first.getUset(),
first.getUread(),
first.getVoltage(),
Instant.EPOCH,
first.getLength() + second.getLength(),
newArray
);
}
public static NMPoint substractPoint(NMPoint point, NMPoint reference) {
public static NumassPoint substractPoint(NumassPoint point, NumassPoint reference) {
int[] array = new int[point.getSpectrum().length];
Arrays.setAll(array, i -> Math.max(0, point.getSpectrum()[i] - reference.getSpectrum()[i]));
return new NMPoint(
point.getUset(),
point.getUread(),
point.getVoltage(),
point.getStartTime(),
point.getLength(),
array
);
}
public static Collection<NMPoint> substractReferencePoint(Collection<NMPoint> points, double uset) {
NMPoint reference = points.stream().filter(it -> it.getUset() == uset).findFirst()
public static Collection<NumassPoint> substractReferencePoint(Collection<NumassPoint> points, double uset) {
NumassPoint reference = points.stream().filter(it -> it.getVoltage() == uset).findFirst()
.orElseThrow(() -> new RuntimeException("Reference point not found"));
return points.stream().map(it -> substractPoint(it, reference)).collect(Collectors.toList());
}

View File

@ -0,0 +1,63 @@
package inr.numass.storage;
import hep.dataforge.tables.DataPoint;
import hep.dataforge.tables.MapPoint;
import java.time.Instant;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* Created by darksnake on 13-Apr-17.
*/
public interface NumassPoint {
String[] dataNames = {"chanel", "count"};
Instant getStartTime();
int getCount(int chanel);
int getCountInWindow(int from, int to);
List<DataPoint> getData();
long getTotalCount();
default Map<Double, Double> getMap(int binning, boolean normalize) {
Map<Double, Double> res = new LinkedHashMap<>();
double norm;
if (normalize) {
norm = getLength();
} else {
norm = 1d;
}
int i = 0;
while (i < RawNMPoint.MAX_CHANEL - binning) {
int start = i;
double sum = 0;
while (i < start + binning) {
sum += getCount(i);
i++;
}
res.put(start + Math.floor(binning / 2d), sum / norm);
}
return res;
}
default List<DataPoint> getData(int binning, boolean normalize) {
return getMap(binning, normalize).entrySet().stream()
.map(entry -> new MapPoint(dataNames, entry.getKey(), entry.getValue()))
.collect(Collectors.toList());
}
double getLength();
double getVoltage();
int[] getSpectrum();
}

View File

@ -0,0 +1,22 @@
package inr.numass.storage;
/**
* Created by darksnake on 13-Apr-17.
*/
public class ProtoUtils {
// public static NumassPoint readProtoPoint(InputStream stream, Function<Channel.Block.Event, Long> peakFinder) throws IOException {
// Point point = NumassProto.Point.parseFrom(stream);
// Channel ch = point.getChannels(0);
// ch.getBlocksList().stream()
// .flatMapToLong(block -> {
// return LongStream.concat(
// block.getPeaks().getAmplitudesList()
// .stream().mapToLong(it -> it.longValue()),
// block.getEventsList().stream()
// .mapToLong(it->)
// )
// });
//
// return new NMPoint();
}
}

View File

@ -0,0 +1,30 @@
syntax = "proto3";
package inr.numass.storage;
message Point {
message Channel {
message Block {
// Необработанное событие
message Event {
uint64 time = 1; //время в наносекундах от начала блока
bytes data = 2; // массив кадра события в формате int16
// ед. измерения - каналы
}
// Обработанные события. Содержат только время и амплитуду сигналов.
// Для экономии места при сериализации амплитуды и времена лежат в
// разных массивах. Амплитуда и время имеющие одинаковые индексы
// соответствуют одному событию
message Peaks {
repeated uint64 times = 1; //время в наносекундах от начала блока
repeated uint64 amplitudes = 2; //амплитуда события в каналах
}
uint64 time = 1; // время начала блока в наносекундах с начала эпохи
repeated Event events = 2; // массив необработанных событий
Peaks peaks = 3; // массив обработанных событий
}
uint64 num = 1; // номер канала
repeated Block blocks = 2; // набранные блоки
}
repeated Channel channels = 1; // массив событий по каналам
}

View File

@ -31,8 +31,8 @@ import hep.dataforge.plots.fx.PlotContainer;
import hep.dataforge.plots.jfreechart.JFreeChartFrame;
import hep.dataforge.storage.commons.JSONMetaWriter;
import hep.dataforge.tables.*;
import inr.numass.storage.NMPoint;
import inr.numass.storage.NumassData;
import inr.numass.storage.NumassPoint;
import inr.numass.utils.TritiumUtils;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
@ -78,7 +78,7 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
private PlotContainer spectrumPlot;
private PlotContainer hvPlot;
private PlottableData spectrumData;
private List<NMPoint> points;
private List<NumassPoint> points;
private ChoiceBox<Integer> detectorBinningSelector;
private CheckBox detectorNormalizeSwitch;
private Button detectorDataExportButton;
@ -214,7 +214,7 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
public void loadData(NumassData data) {
this.data = data;
if (data != null) {
getWorkManager().<List<NMPoint>>startWork("viewer.numass.load", (Work callback) -> {
getWorkManager().<List<NumassPoint>>startWork("viewer.numass.load", (Work callback) -> {
callback.setTitle("Load numass data (" + data.getName() + ")");
points = data.getNMPoints();
@ -263,7 +263,7 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
*
* @param points
*/
private void setupDetectorPane(List<NMPoint> points) {
private void setupDetectorPane(List<NumassPoint> points) {
boolean normalize = detectorNormalizeSwitch.isSelected();
int binning = detectorBinningSelector.getValue();
updateDetectorPane(points, binning, normalize);
@ -285,7 +285,7 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
replace("\\r", "\r\t").replace("\\n", "\n\t"));
}
private void setupSpectrumPane(List<NMPoint> points) {
private void setupSpectrumPane(List<NumassPoint> points) {
if (spectrumData == null) {
spectrumData = new PlottableData("spectrum");
spectrumPlot.getPlot().add(spectrumData);
@ -297,7 +297,7 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
spectrumData.clear();
} else {
spectrumData.fillData(points.stream()
.map((NMPoint point) -> getSpectrumPoint(point, lowChannel, highChannel, getDTime()))
.map((NumassPoint point) -> getSpectrumPoint(point, lowChannel, highChannel, getDTime()))
.collect(Collectors.toList()));
}
}
@ -310,7 +310,7 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
}
}
private DataPoint getSpectrumPoint(NMPoint point, int lowChannel, int upChannel, double dTime) {
private DataPoint getSpectrumPoint(NumassPoint point, int lowChannel, int upChannel, double dTime) {
double u = point.getUread();
return new MapPoint(new String[]{XYAdapter.X_VALUE_KEY, XYAdapter.Y_VALUE_KEY, XYAdapter.Y_ERROR_KEY}, u,
TritiumUtils.countRateWithDeadTime(point,lowChannel, upChannel, dTime),
@ -320,7 +320,7 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
/**
* update detector pane with new data
*/
private void updateDetectorPane(List<NMPoint> points, int binning, boolean normalize) {
private void updateDetectorPane(List<NumassPoint> points, int binning, boolean normalize) {
FXPlotFrame detectorPlotFrame;
if (detectorPlot.getPlot() == null) {
Meta frameMeta = new MetaBuilder("frame")
@ -355,8 +355,8 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
callback.setMaxProgress(points.size());
callback.setProgress(0);
for (NMPoint point : points) {
String seriesName = String.format("%d: %.2f", points.indexOf(point), point.getUset());
for (NumassPoint point : points) {
String seriesName = String.format("%d: %.2f", points.indexOf(point), point.getVoltage());
PlottableData datum = PlottableData.plot(seriesName, new XYAdapter("chanel", "count"), point.getData(binning, normalize));
datum.configure(plottableConfig);
detectorPlotFrame.add(datum);
@ -383,12 +383,12 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
double dTime = getDTime();
ListTable.Builder spectrumDataSet = new ListTable.Builder(names);
for (NMPoint point : points) {
for (NumassPoint point : points) {
spectrumDataSet.row(new MapPoint(names, new Object[]{
point.getUset(),
point.getVoltage(),
point.getUread(),
point.getLength(),
point.getEventsCount(),
point.getTotalCount(),
point.getCountInWindow(loChannel, upChannel),
TritiumUtils.countRateWithDeadTime(point,loChannel, upChannel, dTime),
TritiumUtils.countRateWithDeadTimeErr(point,loChannel, upChannel, dTime),