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: 'groovy'
apply plugin: 'application'
//if (!hasProperty('mainClass')) { //if (!hasProperty('mainClass')) {
// ext.mainClass = 'inr.numass.LaunchGrindShell' // ext.mainClass = 'inr.numass.LaunchGrindShell'
//} //}
//mainClassName = mainClass mainClassName = 'inr.numass.LaunchGrindShell'
description = "Main numass project" description = "Main numass project"

View File

@ -13,7 +13,7 @@ import hep.dataforge.tables.TableFormatBuilder
import inr.numass.storage.NumassData import inr.numass.storage.NumassData
NumassData.metaClass.findPoint{double u -> 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){ 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) { if (i < lowerChannel) {
values[i] = point.getLength()*amp * Math.exp((i as double) / sigma) values[i] = point.getLength()*amp * Math.exp((i as double) / sigma)
} else { } 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) generator.loadSpectrum(chanels, values)
@ -85,7 +85,7 @@ PileUpSimulator buildSimulator(NMPoint point, double cr, NMPoint reference = nul
generator.loadSpectrum(point, reference, lowerChannel, upperChannel); 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) { double adjustCountRate(PileUpSimulator simulator, NMPoint point) {
@ -129,7 +129,7 @@ def keys = res.keySet();
//print spectra for selected point //print spectra for selected point
double u = 16500d; 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" println "\n Spectrum example for U = ${u}\n"
@ -148,9 +148,9 @@ print keys.collect { it + "[pulse]" }.join("\t") + "\t"
println keys.join("\t") println keys.join("\t")
for (int i = 0; i < data.size(); i++) { 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 "${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" 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") 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); //emptySpectra = NumassDataUtils.substractReferencePoint(emptySpectra,18600);
// //
//data = data.collect { point -> //data = data.collect { point ->
// NMPoint ref = emptySpectra.find { it.uset == point.uset } // NMPoint ref = emptySpectra.find { it.u == point.u }
// if (ref) { // if (ref) {
// println "substracting tritium background for point ${point.uset}" // println "substracting tritium background for point ${point.u}"
// NumassDataUtils.substractPoint(point, ref) // NumassDataUtils.substractPoint(point, ref)
// } else { // } else {
// println "point ${point.uset} skipped" // println "point ${point.u} skipped"
// point // point
// } // }
//} //}
def printPoint(Iterable<NMPoint> data, List us, int binning = 20, normalize = true) { 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]] [key, [value]]
}; };
points.eachWithIndex { it, index -> points.eachWithIndex { it, index ->
print "\t${it.uset}" print "\t${it.voltage}"
it.getMapWithBinning(binning, normalize).each { k, v -> it.getMap(binning, normalize).each { k, v ->
spectra[k].add(v) spectra[k].add(v)
} }
} }

View File

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

View File

@ -6,6 +6,7 @@ import hep.dataforge.description.TypedActionDef;
import hep.dataforge.meta.Laminate; import hep.dataforge.meta.Laminate;
import inr.numass.storage.NMPoint; import inr.numass.storage.NMPoint;
import inr.numass.storage.NumassData; import inr.numass.storage.NumassData;
import inr.numass.storage.NumassPoint;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
@ -20,17 +21,16 @@ public class JoinNumassDataAction extends ManyToOneAction<NumassData, NumassData
@Override @Override
protected NumassData execute(Context context, String nodeName, Map<String, NumassData> input, Laminate meta) { protected NumassData execute(Context context, String nodeName, Map<String, NumassData> input, Laminate meta) {
throw new UnsupportedOperationException("not implemented"); throw new UnsupportedOperationException("not implemented");
} }
private NMPoint joinPoint(Collection<NMPoint> points) { private NumassPoint joinPoint(Collection<NumassPoint> points) {
return points.stream().reduce((p1, p2) -> { 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"); throw new RuntimeException("Can't sum points with different Uset");
} }
return new NMPoint( return new NMPoint(
p1.getUset(), (p1.getVoltage() + p2.getVoltage()) / 2,
(p1.getUread() + p2.getUset()) / 2,
p1.getStartTime(), p1.getStartTime(),
p1.getLength() + p2.getLength(), p1.getLength() + p2.getLength(),
IntStream.range(0, p1.getSpectrum().length).map(i -> p1.getSpectrum()[i] * p2.getSpectrum()[i]).toArray() 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 hep.dataforge.tables.*;
import inr.numass.debunch.DebunchReport; import inr.numass.debunch.DebunchReport;
import inr.numass.debunch.FrameAnalizer; import inr.numass.debunch.FrameAnalizer;
import inr.numass.storage.NMPoint; import inr.numass.storage.*;
import inr.numass.storage.NumassData;
import inr.numass.storage.NumassDataLoader;
import inr.numass.storage.RawNMPoint;
import inr.numass.utils.ExpressionUtils; import inr.numass.utils.ExpressionUtils;
import java.io.OutputStream; import java.io.OutputStream;
@ -111,10 +108,10 @@ public class PrepareDataAction extends OneToOneAction<NumassData, Table> {
} }
List<DataPoint> dataList = new ArrayList<>(); List<DataPoint> dataList = new ArrayList<>();
for (NMPoint point : dataFile) { for (NumassPoint point : dataFile) {
long total = point.getEventsCount(); long total = point.getTotalCount();
double uset = utransform.apply(point.getUset()); double uset = utransform.apply(point.getVoltage());
double uread = utransform.apply(point.getUread()); double uread = utransform.apply(point.getUread());
double time = point.getLength(); double time = point.getLength();
int a = getLowerBorder(meta, uset); int a = getLowerBorder(meta, uset);
@ -179,12 +176,12 @@ public class PrepareDataAction extends OneToOneAction<NumassData, Table> {
final String errExpr = corrMeta.getString("err", ""); final String errExpr = corrMeta.getString("err", "");
return new Correction() { return new Correction() {
@Override @Override
public double corr(NMPoint point) { public double corr(NumassPoint point) {
return pointExpression(expr, point); return pointExpression(expr, point);
} }
@Override @Override
public double corrErr(NMPoint point) { public double corrErr(NumassPoint point) {
if (errExpr.isEmpty()) { if (errExpr.isEmpty()) {
return 0; return 0;
} else { } 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 upper = meta.getInt("upperchanel", RawNMPoint.MAX_CHANEL);
int lower = meta.getInt("lowerchanel", 0); int lower = meta.getInt("lowerchanel", 0);
double rejectionprob = meta.getDouble("rejectprob", 1e-10); double rejectionprob = meta.getDouble("rejectprob", 1e-10);
@ -218,7 +215,7 @@ public class PrepareDataAction extends OneToOneAction<NumassData, Table> {
* @param point * @param point
* @return * @return
*/ */
double corr(NMPoint point); double corr(NumassPoint point);
/** /**
* correction coefficient uncertainty * correction coefficient uncertainty
@ -226,11 +223,11 @@ public class PrepareDataAction extends OneToOneAction<NumassData, Table> {
* @param point * @param point
* @return * @return
*/ */
default double corrErr(NMPoint point) { default double corrErr(NumassPoint point) {
return 0; return 0;
} }
default double relativeErr(NMPoint point) { default double relativeErr(NumassPoint point) {
double corrErr = corrErr(point); double corrErr = corrErr(point);
if (corrErr == 0) { if (corrErr == 0) {
return 0; return 0;
@ -242,18 +239,18 @@ public class PrepareDataAction extends OneToOneAction<NumassData, Table> {
private class DeadTimeCorrection implements Correction { private class DeadTimeCorrection implements Correction {
private final Function<NMPoint, Double> deadTimeFunction; private final Function<NumassPoint, Double> deadTimeFunction;
public DeadTimeCorrection(String expr) { public DeadTimeCorrection(String expr) {
deadTimeFunction = point -> pointExpression(expr, point); deadTimeFunction = point -> pointExpression(expr, point);
} }
@Override @Override
public double corr(NMPoint point) { public double corr(NumassPoint point) {
double deadTime = deadTimeFunction.apply(point); double deadTime = deadTimeFunction.apply(point);
if (deadTime > 0) { if (deadTime > 0) {
double factor = deadTime / point.getLength() * point.getEventsCount(); double factor = deadTime / point.getLength() * point.getTotalCount();
// double total = point.getEventsCount(); // double total = point.getTotalCount();
// double time = point.getLength(); // double time = point.getLength();
// return 1d/(1d - factor); // 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.plots.data.XYPlottable;
import hep.dataforge.tables.*; import hep.dataforge.tables.*;
import hep.dataforge.values.ValueType; import hep.dataforge.values.ValueType;
import inr.numass.storage.NMPoint;
import inr.numass.storage.NumassData; import inr.numass.storage.NumassData;
import inr.numass.storage.NumassPoint;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.*; 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) { protected Table execute(Context context, String name, NumassData input, Laminate inputMeta) {
int binning = inputMeta.getInt("binning", 20); int binning = inputMeta.getInt("binning", 20);
boolean normalize = inputMeta.getBoolean("normalize", true); boolean normalize = inputMeta.getBoolean("normalize", true);
List<NMPoint> points = input.getNMPoints(); List<NumassPoint> points = input.getNMPoints();
if (points.isEmpty()) { if (points.isEmpty()) {
getLogger(inputMeta).error("Empty data"); getLogger(inputMeta).error("Empty data");
@ -46,13 +46,13 @@ public class ShowEnergySpectrumAction extends OneToOneAction<NumassData, Table>
//build header //build header
List<String> names = new ArrayList<>(); List<String> names = new ArrayList<>();
for (int i = 0; i < points.size(); i++) { 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() LinkedHashMap<String, Map<Double, Double>> valueMap = points.stream()
.collect(Collectors.toMap( .collect(Collectors.toMap(
p -> names.get(points.indexOf(p)), p -> names.get(points.indexOf(p)),
p -> p.getMapWithBinning(binning, normalize), p -> p.getMap(binning, normalize),
(v1, v2) -> v1, (v1, v2) -> v1,
() -> new LinkedHashMap<>() () -> new LinkedHashMap<>()
)); ));

View File

@ -20,7 +20,7 @@ import hep.dataforge.tables.SimplePointSource;
import hep.dataforge.tables.TableFormat; import hep.dataforge.tables.TableFormat;
import hep.dataforge.values.Value; import hep.dataforge.values.Value;
import inr.numass.storage.NMFile; import inr.numass.storage.NMFile;
import inr.numass.storage.NMPoint; import inr.numass.storage.NumassPoint;
import org.apache.commons.math3.util.Pair; import org.apache.commons.math3.util.Pair;
import java.util.ArrayList; 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){ 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<>(); HashMap<String,Value> map = new HashMap<>();
//Кладем напряжение //Кладем напряжение
map.put(UNAME, Value.of(point.getUset())); map.put(UNAME, Value.of(point.getVoltage()));
double t = point.getLength(); double t = point.getLength();
map.put(TNAME, Value.of(t)); map.put(TNAME, Value.of(t));
@ -73,7 +73,7 @@ public class SlicedData extends SimplePointSource {
} else if(b<a) { } else if(b<a) {
count = point.getCountInWindow(b, a); count = point.getCountInWindow(b, a);
} else{ } else{
count = point.getCountInChanel(a); count = point.getCount(a);
} }
//пихаем все в map //пихаем все в map
if(normalize){ if(normalize){

View File

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

View File

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

View File

@ -7,6 +7,7 @@ package inr.numass.utils;
import inr.numass.storage.NMEvent; import inr.numass.storage.NMEvent;
import inr.numass.storage.NMPoint; import inr.numass.storage.NMPoint;
import inr.numass.storage.NumassPoint;
import inr.numass.storage.RawNMPoint; import inr.numass.storage.RawNMPoint;
import org.apache.commons.math3.random.RandomGenerator; import org.apache.commons.math3.random.RandomGenerator;
@ -53,15 +54,15 @@ public class PileUpSimulator {
return this; return this;
} }
public NMPoint generated() { public NumassPoint generated() {
return new NMPoint(new RawNMPoint(uSet, generated, pointLength)); return new NMPoint(new RawNMPoint(uSet, generated, pointLength));
} }
public NMPoint registered() { public NumassPoint registered() {
return new NMPoint(new RawNMPoint(uSet, registered, pointLength)); return new NMPoint(new RawNMPoint(uSet, registered, pointLength));
} }
public NMPoint pileup() { public NumassPoint pileup() {
return new NMPoint(new RawNMPoint(uSet, pileup, pointLength)); 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.ListTable;
import hep.dataforge.tables.Table; import hep.dataforge.tables.Table;
import inr.numass.data.SpectrumDataAdapter; import inr.numass.data.SpectrumDataAdapter;
import inr.numass.storage.NMPoint; import inr.numass.storage.NumassPoint;
import org.apache.commons.math3.analysis.UnivariateFunction; import org.apache.commons.math3.analysis.UnivariateFunction;
import java.util.HashMap; import java.util.HashMap;
@ -107,11 +107,11 @@ public class TritiumUtils {
return res * 1E-23; 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 wind = p.getCountInWindow(from, to) / p.getLength();
double res; double res;
if (deadTime > 0) { if (deadTime > 0) {
double total = p.getEventsCount(); double total = p.getTotalCount();
// double time = p.getLength(); // double time = p.getLength();
// res = wind / (1 - total * deadTime / time); // res = wind / (1 - total * deadTime / time);
double timeRatio = deadTime / p.getLength(); double timeRatio = deadTime / p.getLength();
@ -122,7 +122,7 @@ public class TritiumUtils {
return res; 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()); return Math.sqrt(countRateWithDeadTime(p, from, to, deadTime) / p.getLength());
} }
@ -133,11 +133,11 @@ public class TritiumUtils {
* @param point * @param point
* @return * @return
*/ */
public static double pointExpression(String expression, NMPoint point) { public static double pointExpression(String expression, NumassPoint point) {
Map<String, Object> exprParams = new HashMap<>(); Map<String, Object> exprParams = new HashMap<>();
exprParams.put("T", point.getLength()); exprParams.put("T", point.getLength());
exprParams.put("U", point.getUread()); 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); exprParams.put("point", point);
return ExpressionUtils.function(expression, exprParams); 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.ListTable;
import hep.dataforge.tables.MapPoint; import hep.dataforge.tables.MapPoint;
import hep.dataforge.tables.Table; 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.analysis.ParametricUnivariateFunction;
import org.apache.commons.math3.exception.DimensionMismatchException; import org.apache.commons.math3.exception.DimensionMismatchException;
import org.apache.commons.math3.fitting.SimpleCurveFitter; import org.apache.commons.math3.fitting.SimpleCurveFitter;
@ -30,7 +30,7 @@ public class UnderflowCorrection {
// private final static int CUTOFF = -200; // private final static int CUTOFF = -200;
// public double get(Logable log, Meta meta, NMPoint point) { // 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")) { // if (meta.hasValue("underflow.function")) {
// return TritiumUtils.pointExpression(meta.getString("underflow.function"), point); // return TritiumUtils.pointExpression(meta.getString("underflow.function"), point);
// } else { // } else {
@ -47,7 +47,7 @@ public class UnderflowCorrection {
// double correction = fitRes[0] * fitRes[1] * (Math.exp(xLow / fitRes[1]) - 1d) / norm + 1d; // double correction = fitRes[0] * fitRes[1] * (Math.exp(xLow / fitRes[1]) - 1d) / norm + 1d;
// return correction; // return correction;
// } catch (Exception ex) { // } 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; // return 1d;
// } // }
// } // }
@ -57,23 +57,23 @@ public class UnderflowCorrection {
// ListTable.Builder builder = new ListTable.Builder("U", "amp", "expConst"); // ListTable.Builder builder = new ListTable.Builder("U", "amp", "expConst");
// for (NMPoint point : data) { // for (NMPoint point : data) {
// double[] fitRes = getUnderflowExpParameters(point, xLow, xHigh, binning); // 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(); // 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 norm = ((double) point.getCountInWindow(xLow, upper)) / point.getLength();
double[] fitRes = getUnderflowExpParameters(point, xLow, xHigh, binning); double[] fitRes = getUnderflowExpParameters(point, xLow, xHigh, binning);
double a = fitRes[0]; double a = fitRes[0];
double sigma = fitRes[1]; 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); ListTable.Builder builder = new ListTable.Builder(pointNames);
for (NMPoint point : data) { for (NumassPoint point : data) {
builder.row(fitPoint(point,xLow,xHigh,upper,binning)); builder.row(fitPoint(point,xLow,xHigh,upper,binning));
} }
return builder.build(); return builder.build();
@ -88,12 +88,12 @@ public class UnderflowCorrection {
* @param xHigh * @param xHigh
* @return * @return
*/ */
private double[] getUnderflowExpParameters(NMPoint point, int xLow, int xHigh, int binning) { private double[] getUnderflowExpParameters(NumassPoint point, int xLow, int xHigh, int binning) {
try { try {
if (xHigh <= xLow) { if (xHigh <= xLow) {
throw new IllegalArgumentException("Wrong borders for underflow calculation"); throw new IllegalArgumentException("Wrong borders for underflow calculation");
} }
List<WeightedObservedPoint> points = point.getMapWithBinning(binning, false) List<WeightedObservedPoint> points = point.getMap(binning, false)
.entrySet().stream() .entrySet().stream()
.filter(entry -> entry.getKey() >= xLow && entry.getKey() <= xHigh) .filter(entry -> entry.getKey() >= xLow && entry.getKey() <= xHigh)
.map(p -> new WeightedObservedPoint( .map(p -> new WeightedObservedPoint(

View File

@ -1,4 +1,36 @@
dependencies { buildscript {
compile "hep.dataforge:dataforge-storage" //project(':dataforge-storage') 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.") @ValueDef(name = "numass.name", info = "The name of this data file.")
public class NMFile extends NamedMetaHolder implements NumassData { public class NMFile extends NamedMetaHolder implements NumassData {
private final List<NMPoint> points; private final List<NumassPoint> points;
public NMFile(RawNMFile file) { public NMFile(RawNMFile file) {
super(file.getName(), file.meta()); super(file.getName(), file.meta());
@ -60,7 +60,7 @@ public class NMFile extends NamedMetaHolder implements NumassData {
} }
@Override @Override
public Stream<NMPoint> stream() { public Stream<NumassPoint> stream() {
return points.stream(); return points.stream();
} }

View File

@ -19,30 +19,27 @@ 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.*; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream; import java.util.stream.IntStream;
import static java.util.Arrays.sort;
/** /**
* @author Darksnake * @author Darksnake
*/ */
public class NMPoint { public class NMPoint implements NumassPoint {
//TODO andThen to annotated and move some parameters to meta //TODO andThen to annotated and move some parameters to meta
static final String[] dataNames = {"chanel", "count"};
private final int[] spectrum; private final int[] spectrum;
private Instant startTime; private Instant startTime;
private long eventsCount; private long eventsCount;
private double pointLength; private double pointLength;
private double uread; private double u;
private double uset;
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.startTime = startTime;
this.pointLength = pointLength; this.pointLength = pointLength;
this.spectrum = spectrum; this.spectrum = spectrum;
this.uread = uread; this.u = u;
this.uset = uset;
this.eventsCount = IntStream.of(spectrum).sum(); this.eventsCount = IntStream.of(spectrum).sum();
} }
@ -52,8 +49,8 @@ public class NMPoint {
} }
this.pointLength = point.getLength(); this.pointLength = point.getLength();
this.uset = point.getUset(); this.u = point.getUset();
this.uread = point.getUread(); // this.uread = point.getUread();
this.startTime = point.getStartTime(); this.startTime = point.getStartTime();
this.eventsCount = point.getEventsCount(); this.eventsCount = point.getEventsCount();
spectrum = calculateSpectrum(point); spectrum = calculateSpectrum(point);
@ -74,33 +71,10 @@ public class NMPoint {
return result; 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 * @return the absouteTime
*/ */
@Override
public Instant getStartTime() { public Instant getStartTime() {
if (startTime == null) { if (startTime == null) {
return Instant.EPOCH; return Instant.EPOCH;
@ -109,10 +83,12 @@ public class NMPoint {
} }
} }
public int getCountInChanel(int chanel) { @Override
public int getCount(int chanel) {
return spectrum[chanel]; return spectrum[chanel];
} }
@Override
public int getCountInWindow(int from, int to) { public int getCountInWindow(int from, int to) {
int res = 0; int res = 0;
for (int i = from; i <= to; i++) { for (int i = from; i <= to; i++) {
@ -124,6 +100,7 @@ public class NMPoint {
return res; return res;
} }
@Override
public List<DataPoint> getData() { public List<DataPoint> getData() {
List<DataPoint> data = new ArrayList<>(); List<DataPoint> data = new ArrayList<>();
for (int i = 0; i < RawNMPoint.MAX_CHANEL; i++) { for (int i = 0; i < RawNMPoint.MAX_CHANEL; i++) {
@ -138,72 +115,11 @@ public class NMPoint {
* *
* @return * @return
*/ */
public long getEventsCount() { @Override
public long getTotalCount() {
return eventsCount; 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 * @return the overflow
@ -215,24 +131,20 @@ public class NMPoint {
/** /**
* @return the pointLength * @return the pointLength
*/ */
@Override
public double getLength() { public double getLength() {
return pointLength; return pointLength;
} }
/** /**
* @return the uread * @return the u
*/ */
public double getUread() { @Override
return uread; public double getVoltage() {
} return u;
/**
* @return the uset
*/
public double getUset() {
return uset;
} }
@Override
public int[] getSpectrum() { public int[] getSpectrum() {
return spectrum; return spectrum;
} }

View File

@ -20,21 +20,21 @@ import java.util.stream.Stream;
/** /**
* @author <a href="mailto:altavir@gmail.com">Alexander Nozik</a> * @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(); String getDescription();
@Override @Override
Meta meta(); Meta meta();
Stream<NMPoint> stream(); Stream<NumassPoint> stream();
@Override @Override
default Iterator<NMPoint> iterator() { default Iterator<NumassPoint> iterator() {
return stream().iterator(); return stream().iterator();
} }
default List<NMPoint> getNMPoints() { default List<NumassPoint> getNMPoints() {
return stream().collect(Collectors.toList()); return stream().collect(Collectors.toList());
} }
@ -52,28 +52,14 @@ public interface NumassData extends Named, Annotated, Iterable<NMPoint> {
* @param U * @param U
* @return * @return
*/ */
default NMPoint getByUset(double U) { default NumassPoint getByVoltage(double U) {
for (NMPoint point : this) { for (NumassPoint point : this) {
if (point.getUset() == U) { if (point.getVoltage() == U) {
return point; return point;
} }
} }
return null; 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 * @param transformation
* @return * @return
*/ */
private NMPoint readPoint(Envelope envelope, Function<RawNMPoint, NMPoint> transformation) { private NumassPoint readPoint(Envelope envelope, Function<RawNMPoint, NumassPoint> transformation) {
return transformation.apply(readRawPoint(envelope)); return transformation.apply(readRawPoint(envelope));
} }
@ -234,7 +234,7 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
* @param envelope * @param envelope
* @return * @return
*/ */
public NMPoint readPoint(Envelope envelope) { public NumassPoint readPoint(Envelope envelope) {
return readPoint(envelope, NMPoint::new); return readPoint(envelope, NMPoint::new);
} }
@ -281,11 +281,11 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
} }
@Override @Override
public Stream<NMPoint> stream() { public Stream<NumassPoint> stream() {
return this.getPoints().map(this::readPoint); 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()); 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 * @param transform
* @return * @return
*/ */
public NumassData applyRawTransformation(Function<RawNMPoint, NMPoint> transform) { public NumassData applyRawTransformation(Function<RawNMPoint, NumassPoint> transform) {
return new NumassData() { return new NumassData() {
@Override @Override
public String getDescription() { public String getDescription() {
@ -373,7 +373,7 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
} }
@Override @Override
public Stream<NMPoint> stream() { public Stream<NumassPoint> stream() {
return NumassDataLoader.this.stream(); return NumassDataLoader.this.stream();
} }

View File

@ -13,11 +13,11 @@ import java.util.stream.Stream;
*/ */
public class NumassDataUtils { public class NumassDataUtils {
public static Collection<NMPoint> joinSpectra(Stream<NumassData> spectra) { public static Collection<NumassPoint> joinSpectra(Stream<NumassData> spectra) {
Map<Double, NMPoint> map = new LinkedHashMap<>(); Map<Double, NumassPoint> map = new LinkedHashMap<>();
spectra.forEach(datum -> { spectra.forEach(datum -> {
datum.forEach(point -> { datum.forEach(point -> {
double uset = point.getUset(); double uset = point.getVoltage();
if (map.containsKey(uset)) { if (map.containsKey(uset)) {
map.put(uset, join(point, map.get(uset))); map.put(uset, join(point, map.get(uset)));
} else { } else {
@ -35,35 +35,33 @@ public class NumassDataUtils {
* @param second * @param second
* @return * @return
*/ */
public static NMPoint join(NMPoint first, NMPoint second) { public static NumassPoint join(NumassPoint first, NumassPoint second) {
if (first.getUset() != second.getUset()) { if (first.getVoltage() != second.getVoltage()) {
throw new RuntimeException("Voltage mismatch"); throw new RuntimeException("Voltage mismatch");
} }
int[] newArray = new int[first.getSpectrum().length]; int[] newArray = new int[first.getSpectrum().length];
Arrays.setAll(newArray, i -> first.getSpectrum()[i] + second.getSpectrum()[i]); Arrays.setAll(newArray, i -> first.getSpectrum()[i] + second.getSpectrum()[i]);
return new NMPoint( return new NMPoint(
first.getUset(), first.getVoltage(),
first.getUread(),
Instant.EPOCH, Instant.EPOCH,
first.getLength() + second.getLength(), first.getLength() + second.getLength(),
newArray newArray
); );
} }
public static NMPoint substractPoint(NMPoint point, NMPoint reference) { public static NumassPoint substractPoint(NumassPoint point, NumassPoint reference) {
int[] array = new int[point.getSpectrum().length]; int[] array = new int[point.getSpectrum().length];
Arrays.setAll(array, i -> Math.max(0, point.getSpectrum()[i] - reference.getSpectrum()[i])); Arrays.setAll(array, i -> Math.max(0, point.getSpectrum()[i] - reference.getSpectrum()[i]));
return new NMPoint( return new NMPoint(
point.getUset(), point.getVoltage(),
point.getUread(),
point.getStartTime(), point.getStartTime(),
point.getLength(), point.getLength(),
array array
); );
} }
public static Collection<NMPoint> substractReferencePoint(Collection<NMPoint> points, double uset) { public static Collection<NumassPoint> substractReferencePoint(Collection<NumassPoint> points, double uset) {
NMPoint reference = points.stream().filter(it -> it.getUset() == uset).findFirst() NumassPoint reference = points.stream().filter(it -> it.getVoltage() == uset).findFirst()
.orElseThrow(() -> new RuntimeException("Reference point not found")); .orElseThrow(() -> new RuntimeException("Reference point not found"));
return points.stream().map(it -> substractPoint(it, reference)).collect(Collectors.toList()); 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.plots.jfreechart.JFreeChartFrame;
import hep.dataforge.storage.commons.JSONMetaWriter; import hep.dataforge.storage.commons.JSONMetaWriter;
import hep.dataforge.tables.*; import hep.dataforge.tables.*;
import inr.numass.storage.NMPoint;
import inr.numass.storage.NumassData; import inr.numass.storage.NumassData;
import inr.numass.storage.NumassPoint;
import inr.numass.utils.TritiumUtils; import inr.numass.utils.TritiumUtils;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
@ -78,7 +78,7 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
private PlotContainer spectrumPlot; private PlotContainer spectrumPlot;
private PlotContainer hvPlot; private PlotContainer hvPlot;
private PlottableData spectrumData; private PlottableData spectrumData;
private List<NMPoint> points; private List<NumassPoint> points;
private ChoiceBox<Integer> detectorBinningSelector; private ChoiceBox<Integer> detectorBinningSelector;
private CheckBox detectorNormalizeSwitch; private CheckBox detectorNormalizeSwitch;
private Button detectorDataExportButton; private Button detectorDataExportButton;
@ -214,7 +214,7 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
public void loadData(NumassData data) { public void loadData(NumassData data) {
this.data = data; this.data = data;
if (data != null) { 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() + ")"); callback.setTitle("Load numass data (" + data.getName() + ")");
points = data.getNMPoints(); points = data.getNMPoints();
@ -263,7 +263,7 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
* *
* @param points * @param points
*/ */
private void setupDetectorPane(List<NMPoint> points) { private void setupDetectorPane(List<NumassPoint> points) {
boolean normalize = detectorNormalizeSwitch.isSelected(); boolean normalize = detectorNormalizeSwitch.isSelected();
int binning = detectorBinningSelector.getValue(); int binning = detectorBinningSelector.getValue();
updateDetectorPane(points, binning, normalize); updateDetectorPane(points, binning, normalize);
@ -285,7 +285,7 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
replace("\\r", "\r\t").replace("\\n", "\n\t")); replace("\\r", "\r\t").replace("\\n", "\n\t"));
} }
private void setupSpectrumPane(List<NMPoint> points) { private void setupSpectrumPane(List<NumassPoint> points) {
if (spectrumData == null) { if (spectrumData == null) {
spectrumData = new PlottableData("spectrum"); spectrumData = new PlottableData("spectrum");
spectrumPlot.getPlot().add(spectrumData); spectrumPlot.getPlot().add(spectrumData);
@ -297,7 +297,7 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
spectrumData.clear(); spectrumData.clear();
} else { } else {
spectrumData.fillData(points.stream() spectrumData.fillData(points.stream()
.map((NMPoint point) -> getSpectrumPoint(point, lowChannel, highChannel, getDTime())) .map((NumassPoint point) -> getSpectrumPoint(point, lowChannel, highChannel, getDTime()))
.collect(Collectors.toList())); .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(); double u = point.getUread();
return new MapPoint(new String[]{XYAdapter.X_VALUE_KEY, XYAdapter.Y_VALUE_KEY, XYAdapter.Y_ERROR_KEY}, u, return new MapPoint(new String[]{XYAdapter.X_VALUE_KEY, XYAdapter.Y_VALUE_KEY, XYAdapter.Y_ERROR_KEY}, u,
TritiumUtils.countRateWithDeadTime(point,lowChannel, upChannel, dTime), TritiumUtils.countRateWithDeadTime(point,lowChannel, upChannel, dTime),
@ -320,7 +320,7 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
/** /**
* update detector pane with new data * 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; FXPlotFrame detectorPlotFrame;
if (detectorPlot.getPlot() == null) { if (detectorPlot.getPlot() == null) {
Meta frameMeta = new MetaBuilder("frame") Meta frameMeta = new MetaBuilder("frame")
@ -355,8 +355,8 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
callback.setMaxProgress(points.size()); callback.setMaxProgress(points.size());
callback.setProgress(0); callback.setProgress(0);
for (NMPoint point : points) { for (NumassPoint point : points) {
String seriesName = String.format("%d: %.2f", points.indexOf(point), point.getUset()); String seriesName = String.format("%d: %.2f", points.indexOf(point), point.getVoltage());
PlottableData datum = PlottableData.plot(seriesName, new XYAdapter("chanel", "count"), point.getData(binning, normalize)); PlottableData datum = PlottableData.plot(seriesName, new XYAdapter("chanel", "count"), point.getData(binning, normalize));
datum.configure(plottableConfig); datum.configure(plottableConfig);
detectorPlotFrame.add(datum); detectorPlotFrame.add(datum);
@ -383,12 +383,12 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
double dTime = getDTime(); double dTime = getDTime();
ListTable.Builder spectrumDataSet = new ListTable.Builder(names); ListTable.Builder spectrumDataSet = new ListTable.Builder(names);
for (NMPoint point : points) { for (NumassPoint point : points) {
spectrumDataSet.row(new MapPoint(names, new Object[]{ spectrumDataSet.row(new MapPoint(names, new Object[]{
point.getUset(), point.getVoltage(),
point.getUread(), point.getUread(),
point.getLength(), point.getLength(),
point.getEventsCount(), point.getTotalCount(),
point.getCountInWindow(loChannel, upChannel), point.getCountInWindow(loChannel, upChannel),
TritiumUtils.countRateWithDeadTime(point,loChannel, upChannel, dTime), TritiumUtils.countRateWithDeadTime(point,loChannel, upChannel, dTime),
TritiumUtils.countRateWithDeadTimeErr(point,loChannel, upChannel, dTime), TritiumUtils.countRateWithDeadTimeErr(point,loChannel, upChannel, dTime),