Numass statistical count rate

This commit is contained in:
darksnake 2017-06-27 16:24:02 +03:00
parent 36db0c3811
commit c08e52a398
27 changed files with 247 additions and 204 deletions

View File

@ -1,5 +1,5 @@
buildscript { buildscript {
ext.kotlin_version = '1.1.2-5' ext.kotlin_version = '1.1.3'
repositories { repositories {
mavenCentral() mavenCentral()
@ -29,7 +29,7 @@ dependencies {
//graphics //graphics
compile 'org.controlsfx:controlsfx:8.40.12' compile 'org.controlsfx:controlsfx:8.40.12'
compile "no.tornado:tornadofx:1.7.5" compile "no.tornado:tornadofx:1.7.8"
} }
task installAll(type: Copy) { task installAll(type: Copy) {

View File

@ -65,13 +65,13 @@ class PKT8ViewConnection : DeviceViewConnection<PKT8Device>(), MeasurementListen
private var plotButton: ToggleButton by singleAssign() private var plotButton: ToggleButton by singleAssign()
private var logButton: ToggleButton by singleAssign() private var logButton: ToggleButton by singleAssign()
private val logWindow = FragmentWindow(LogFragment().apply { // private val logWindow = FragmentWindow(LogFragment().apply {
addLogHandler(device.logger) // addLogHandler(device.logger)
}) // })
// need those to have strong references to listeners // need those to have strong references to listeners
private val plotView = CryoPlotView(); private val plotView = CryoPlotView();
private val plotWindow = FragmentWindow(FXFragment.buildFromNode(plotView.title) { plotView.root }) // private val plotWindow = FragmentWindow(FXFragment.buildFromNode(plotView.title) { plotView.root })
override val root = borderpane { override val root = borderpane {
top { top {
@ -92,12 +92,16 @@ class PKT8ViewConnection : DeviceViewConnection<PKT8Device>(), MeasurementListen
plotButton = togglebutton("Plot") { plotButton = togglebutton("Plot") {
isSelected = false isSelected = false
plotWindow.bindTo(this) FragmentWindow.build(this) { FXFragment.buildFromNode(plotView.title) { plotView.root } }
} }
logButton = togglebutton("Log") { logButton = togglebutton("Log") {
isSelected = false isSelected = false
logWindow.bindTo(this) FragmentWindow.build(this) {
LogFragment().apply {
addLogHandler(device.logger)
}
}
} }
} }
} }

View File

@ -109,9 +109,9 @@ class MspViewConnection() : DeviceViewConnection<MspDevice>(), DeviceListener, N
} }
} }
private val logWindow = FragmentWindow(LogFragment().apply { // private val logWindow = FragmentWindow(LogFragment().apply {
addLogHandler(device.logger) // addLogHandler(device.logger)
}) // })
val filamentProperty = SimpleObjectProperty<Int>(this, "filament", 1).apply { val filamentProperty = SimpleObjectProperty<Int>(this, "filament", 1).apply {
addListener { _, oldValue, newValue -> addListener { _, oldValue, newValue ->
@ -173,7 +173,9 @@ class MspViewConnection() : DeviceViewConnection<MspDevice>(), DeviceListener, N
togglebutton("Log") { togglebutton("Log") {
isSelected = false isSelected = false
logWindow.bindTo(this) FragmentWindow.build(this){LogFragment().apply {
addLogHandler(device.logger)
}}
} }
} }
} }

View File

@ -141,7 +141,7 @@ abstract class DeviceViewConnection<D : Device> : Component(), Connection, Devic
} }
togglebutton("View") { togglebutton("View") {
isSelected = false isSelected = false
FragmentWindow(FXFragment.buildFromNode(device.name) { fxNode }).bindTo(this) FragmentWindow.build(this){FXFragment.buildFromNode(device.name) { fxNode }}
} }
} }
} }

View File

@ -74,9 +74,9 @@ class VacCollectorViewConnection : DeviceViewConnection<VacCollectorDevice>() {
setValue("thickness", 3) setValue("thickness", 3)
} }
private val logWindow = FragmentWindow(LogFragment().apply { // private val logWindow = FragmentWindow(LogFragment().apply {
addLogHandler(device.logger) // addLogHandler(device.logger)
}) // })
override val root = borderpane { override val root = borderpane {
top { top {
@ -89,7 +89,9 @@ class VacCollectorViewConnection : DeviceViewConnection<VacCollectorDevice>() {
separator(Orientation.VERTICAL) separator(Orientation.VERTICAL)
togglebutton("Log") { togglebutton("Log") {
isSelected = false isSelected = false
logWindow.bindTo(this) FragmentWindow.build(this){LogFragment().apply {
addLogHandler(device.logger)
}}
} }
} }
} }

View File

@ -23,35 +23,37 @@ import java.io.*;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneOffset; import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner; import java.util.Scanner;
/** /**
* *
* @author Darksnake, based on program by S.V.Zadorozhny, 1996 * @author Darksnake, based on program by S.V.Zadorozhny, 1996
*/ */
public class NumassDataReader { public class LegacyDataReader {
private final InputStream stream; private final InputStream stream;
private String name; private String name;
private double HVdev = 2.468555393226049; private double HVdev = 2.468555393226049;
private boolean noUset = false; private boolean noUset = false;
public NumassDataReader(Binary file, Meta config) throws IOException { public LegacyDataReader(Binary file, Meta config) throws IOException {
this(file.getStream(), config.getString(FileDataFactory.FILE_NAME_KEY), config); this(file.getStream(), config.getString(FileDataFactory.FILE_NAME_KEY), config);
} }
public NumassDataReader(File file) throws IOException { public LegacyDataReader(File file) throws IOException {
this(new FileInputStream(file), file.getName(), Meta.empty()); this(new FileInputStream(file), file.getName(), Meta.empty());
} }
public NumassDataReader(String file, String fname, Meta config) throws FileNotFoundException { public LegacyDataReader(String file, String fname, Meta config) throws FileNotFoundException {
this(new FileInputStream(file), fname, config); this(new FileInputStream(file), fname, config);
if ((fname == null) || (fname.isEmpty())) { if ((fname == null) || (fname.isEmpty())) {
name = file; name = file;
} }
} }
public NumassDataReader(InputStream is, String fname, Meta config) { public LegacyDataReader(InputStream is, String fname, Meta config) {
this.stream = new BufferedInputStream(is); this.stream = new BufferedInputStream(is);
this.name = fname; this.name = fname;
HVdev = config.getDouble("HVdev", 2.468555393226049); HVdev = config.getDouble("HVdev", 2.468555393226049);
@ -204,12 +206,14 @@ public class NumassDataReader {
} }
lab = readByte(); lab = readByte();
List<NMEvent> events = new ArrayList<>();
while (lab == 0xBF) { while (lab == 0xBF) {
skip(4);//badHV skip(4);//badHV
lab = readByte(); lab = readByte();
} }
do { do {
point.putEvent(readEvent(lab, timeDiv)); events.add(readEvent(lab, timeDiv));
lab = readByte(); lab = readByte();
} while (lab != 0xAF); } while (lab != 0xAF);
@ -226,7 +230,6 @@ public class NumassDataReader {
absoluteTime = absoluteTime.plusDays(1); absoluteTime = absoluteTime.plusDays(1);
} }
point.setStartTime(absoluteTime.toInstant(ZoneOffset.UTC));
rx = readBlock(4); rx = readBlock(4);
int Uread = rx[2] + 256 * rx[3]; int Uread = rx[2] + 256 * rx[3];
@ -234,15 +237,14 @@ public class NumassDataReader {
skip(21); skip(21);
point.setLength(time_out); double uset;
point.setUread(Uread / 10d / HVdev);
if (noUset) { if (noUset) {
point.setUset(Uread / 10d / HVdev); uset = Uread / 10d / HVdev;
} else { } else {
point.setUset(voltage / 10d); uset = voltage / 10d;
} }
return point; return new RawNMPoint(uset, Uread / 10d / HVdev, events, time_out, absoluteTime.toInstant(ZoneOffset.UTC));
} }
private long readTime() throws IOException { private long readTime() throws IOException {

View File

@ -47,11 +47,11 @@ public class NMFile extends NamedMetaHolder implements NumassData {
} }
public static NMFile readStream(InputStream is, String fname, Meta config) throws IOException { public static NMFile readStream(InputStream is, String fname, Meta config) throws IOException {
return new NMFile(new NumassDataReader(is, fname, config).read()); return new NMFile(new LegacyDataReader(is, fname, config).read());
} }
public static NMFile readFile(File file) throws IOException { public static NMFile readFile(File file) throws IOException {
return new NMFile(new NumassDataReader(file).read()); return new NMFile(new LegacyDataReader(file).read());
} }
@Override @Override

View File

@ -10,6 +10,7 @@ import hep.dataforge.meta.Meta;
import hep.dataforge.meta.Metoid; import hep.dataforge.meta.Metoid;
import hep.dataforge.names.Named; import hep.dataforge.names.Named;
import hep.dataforge.tables.Table; import hep.dataforge.tables.Table;
import org.jetbrains.annotations.NotNull;
import java.time.Instant; import java.time.Instant;
import java.util.Iterator; import java.util.Iterator;
@ -29,6 +30,7 @@ public interface NumassData extends Named, Metoid, Iterable<NumassPoint> {
Stream<NumassPoint> stream(); Stream<NumassPoint> stream();
@NotNull
@Override @Override
default Iterator<NumassPoint> iterator() { default Iterator<NumassPoint> iterator() {
return stream().iterator(); return stream().iterator();

View File

@ -45,7 +45,7 @@ public class NumassDataUtils {
} }
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 NumassPointImpl(
first.getVoltage(), first.getVoltage(),
Instant.EPOCH, Instant.EPOCH,
first.getLength() + second.getLength(), first.getLength() + second.getLength(),
@ -56,7 +56,7 @@ public class NumassDataUtils {
public static NumassPoint substractPoint(NumassPoint point, NumassPoint 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 NumassPointImpl(
point.getVoltage(), point.getVoltage(),
point.getStartTime(), point.getStartTime(),
point.getLength(), point.getLength(),

View File

@ -26,7 +26,7 @@ import java.util.stream.IntStream;
/** /**
* @author Darksnake * @author Darksnake
*/ */
public class NMPoint implements NumassPoint { public class NumassPointImpl implements NumassPoint {
//TODO andThen to annotated and move some parameters to meta //TODO andThen to annotated and move some parameters to meta
private final int[] spectrum; private final int[] spectrum;
private Instant startTime; private Instant startTime;
@ -34,7 +34,7 @@ public class NMPoint implements NumassPoint {
private double pointLength; private double pointLength;
private double u; private double u;
public NMPoint(double u, Instant startTime, double pointLength, int[] spectrum) { public NumassPointImpl(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;

View File

@ -27,7 +27,7 @@ public class PointBuilders {
)),0 )),0
); );
return new NMPoint(u, startTime, pointLength, spectrum); return new NumassPointImpl(u, startTime, pointLength, spectrum);
} }
private static int[] calculateSpectrum(RawNMPoint point) { private static int[] calculateSpectrum(RawNMPoint point) {
@ -37,7 +37,7 @@ public class PointBuilders {
@NotNull @NotNull
public static NumassPoint readRawPoint(@NotNull RawNMPoint point) { public static NumassPoint readRawPoint(@NotNull RawNMPoint point) {
return new NMPoint(point.getUset(), point.getStartTime(), point.getLength(), calculateSpectrum(point)); return new NumassPointImpl(point.getUset(), point.getStartTime(), point.getLength(), calculateSpectrum(point));
} }
private static int[] count(IntStream stream, int maxChannel) { private static int[] count(IntStream stream, int maxChannel) {

View File

@ -82,7 +82,7 @@ public class RawNMFile extends NamedMetaHolder {
for (RawNMPoint point : points) { for (RawNMPoint point : points) {
if (point.getUset() == U) { if (point.getUset() == U) {
if (res == null) { if (res == null) {
res = point.clone(); res = point;
} else { } else {
res = res.merge(point); res = res.merge(point);
} }
@ -104,7 +104,7 @@ public class RawNMFile extends NamedMetaHolder {
for (RawNMPoint point : points) { for (RawNMPoint point : points) {
if (point.getUread() == U) { if (point.getUread() == U) {
if (res == null) { if (res == null) {
res = point.clone(); res = point;
} else { } else {
res = res.merge(point); res = res.merge(point);
} }
@ -120,17 +120,17 @@ public class RawNMFile extends NamedMetaHolder {
return points; return points;
} }
public void putEvent(double U, short chanel, double time) { // public void putEvent(double U, short chanel, double time) {
for (RawNMPoint point : this.getData()) { // for (RawNMPoint point : this.getData()) {
if (U == point.getUread()) { // if (U == point.getUread()) {
point.putEvent(new NMEvent(chanel, time)); // point.putEvent(new NMEvent(chanel, time));
return; // return;
} // }
} // }
RawNMPoint newpoint = new RawNMPoint(); // RawNMPoint newpoint = new RawNMPoint();
newpoint.putEvent(new NMEvent(chanel, time)); // newpoint.putEvent(new NMEvent(chanel, time));
this.putPoint(newpoint); // this.putPoint(newpoint);
} // }
public void putPoint(RawNMPoint point) { public void putPoint(RawNMPoint point) {
points.add(point); points.add(point);

View File

@ -24,7 +24,7 @@ import java.util.List;
* *
* @author Darksnake * @author Darksnake
*/ */
public class RawNMPoint implements Cloneable { public class RawNMPoint {
public static final int MAX_EVENTS_PER_POINT = 260000; public static final int MAX_EVENTS_PER_POINT = 260000;
public static int MAX_CHANEL = 4095; public static int MAX_CHANEL = 4095;
@ -65,24 +65,22 @@ public class RawNMPoint implements Cloneable {
length = Double.NaN; length = Double.NaN;
} }
@Override // @Override
public RawNMPoint clone() { // public RawNMPoint clone() {
ArrayList<NMEvent> newevents = new ArrayList<>(); // ArrayList<NMEvent> newevents = new ArrayList<>();
for (NMEvent event : this.getEvents()) { // newevents.addAll(this.getEvents());
newevents.add(event); // return new RawNMPoint(getUset(), getUread(), newevents, getLength());
} // }
return new RawNMPoint(getUset(), getUread(), newevents, getLength());
}
public Instant getStartTime() { public Instant getStartTime() {
return startTime; return startTime;
} }
public double getCR() { public double getCr() {
return getEventsCount() / getLength(); return getEventsCount() / getLength();
} }
public double getCRError() { public double getCrError() {
return Math.sqrt(getEventsCount()) / getLength(); return Math.sqrt(getEventsCount()) / getLength();
} }
@ -99,6 +97,7 @@ public class RawNMPoint implements Cloneable {
/** /**
* Measurement time * Measurement time
*
* @return the tset * @return the tset
*/ */
public double getLength() { public double getLength() {
@ -131,18 +130,18 @@ public class RawNMPoint implements Cloneable {
} }
public RawNMPoint merge(RawNMPoint point) { public RawNMPoint merge(RawNMPoint point) {
RawNMPoint res = this.clone(); List<NMEvent> events = new ArrayList<>(this.events);
for (NMEvent newEvent : point.getEvents()) { for (NMEvent newEvent : point.getEvents()) {
res.putEvent(new NMEvent(newEvent.getChanel(), newEvent.getTime() + this.getLength())); events.add(new NMEvent(newEvent.getChanel(), newEvent.getTime() + this.getLength()));
} }
res.length += point.getLength(); double length = this.length + point.length;
res.uread = (this.uread + point.uread) / 2; double uread = (this.uread + point.uread) / 2;
return res; return new RawNMPoint(this.uset, uread, events, length, this.startTime);
} }
void putEvent(NMEvent event) { // void putEvent(NMEvent event) {
events.add(event); // events.add(event);
} // }
public RawNMPoint selectChanels(int from, int to) { public RawNMPoint selectChanels(int from, int to) {
assert to > from; assert to > from;
@ -156,30 +155,30 @@ public class RawNMPoint implements Cloneable {
return new RawNMPoint(getUset(), getUread(), res, getLength()); return new RawNMPoint(getUset(), getUread(), res, getLength());
} }
void setStartTime(Instant absouteTime) { // void setStartTime(Instant absouteTime) {
this.startTime = absouteTime; // this.startTime = absouteTime;
} // }
//
// /**
// * @param tset the tset to set
// */
// void setLength(double tset) {
// this.length = tset;
// }
/** // /**
* @param tset the tset to set // * @param Uread the Uread to set
*/ // */
void setLength(double tset) { // void setUread(double Uread) {
this.length = tset; // assert Uread >= 0;
} // this.uread = Uread;
// }
/** //
* @param Uread the Uread to set // /**
*/ // * @param Uset the Uset to set
void setUread(double Uread) { // */
assert Uread >= 0; // void setUset(double Uset) {
this.uread = Uread; // this.uset = Uset;
} // }
/**
* @param Uset the Uset to set
*/
void setUset(double Uset) {
this.uset = Uset;
}
} }

View File

@ -21,6 +21,9 @@ import hep.dataforge.io.ColumnedDataReader;
import hep.dataforge.io.envelopes.Envelope; import hep.dataforge.io.envelopes.Envelope;
import hep.dataforge.meta.Meta; import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaBuilder; import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.providers.Provider;
import hep.dataforge.providers.Provides;
import hep.dataforge.providers.ProvidesNames;
import hep.dataforge.storage.api.ObjectLoader; import hep.dataforge.storage.api.ObjectLoader;
import hep.dataforge.storage.api.Storage; import hep.dataforge.storage.api.Storage;
import hep.dataforge.storage.filestorage.FileEnvelope; import hep.dataforge.storage.filestorage.FileEnvelope;
@ -49,13 +52,11 @@ import java.util.stream.Stream;
* *
* @author darksnake * @author darksnake
*/ */
public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Envelope>, NumassData { public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Envelope>, NumassData, Provider {
public static NumassDataLoader fromFile(Storage storage, Path zipFile) throws IOException { public static NumassDataLoader fromFile(Storage storage, Path zipFile) throws IOException {
throw new UnsupportedOperationException("TODO"); throw new UnsupportedOperationException("TODO");
// FileObject zipRoot = VFS.getManager().createFileSystem(zipFile);
// return fromDir(storage, zipRoot, zipFile.getName().getBaseName());
} }
@ -101,19 +102,6 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
return new NumassDataLoader(storage, name, annotation, items); return new NumassDataLoader(storage, name, annotation, items);
} }
// private static Envelope readFile(Path file) {
// String fileName = file.getFileName().toString();
// if (fileName.equals(META_FRAGMENT_NAME)
// || fileName.equals(HV_FRAGMENT_NAME)
// || fileName.startsWith(POINT_FRAGMENT_NAME)) {
// return FileEnvelope.open(file, true);
// } else {
// return null;
// }
// //}
// }
/** /**
* "start_time": "2016-04-20T04:08:50", * "start_time": "2016-04-20T04:08:50",
* *
@ -226,7 +214,7 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
* @param envelope * @param envelope
* @return * @return
*/ */
public NumassPoint readPoint(Envelope envelope) { private NumassPoint readPoint(Envelope envelope) {
return readPoint(envelope, PointBuilders::readRawPoint); return readPoint(envelope, PointBuilders::readRawPoint);
} }
@ -347,6 +335,26 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
} }
@Override
public String defaultTarget() {
return "nmPoint";
}
@Provides("nmPoint")
public Optional<NumassPoint> optPoint(String u) {
return stream().filter(it -> it.getVoltage() == Double.parseDouble(u)).findFirst();
}
@ProvidesNames("nmPoint")
public Stream<String> listHV() {
return stream().map(it -> Double.toString(it.getVoltage()));
}
@Provides("rawPoint")
public Optional<RawNMPoint> optRawPoint(String u) {
return this.getPoints().map(this::readRawPoint).filter(it -> it.getUset() == Double.parseDouble(u)).findFirst();
}
/** /**
* Return new NumassData using given transformation for each point * Return new NumassData using given transformation for each point
* *

View File

@ -0,0 +1,38 @@
package inr.numass.data
import groovy.transform.CompileStatic
/**
* Created by darksnake on 27-Jun-17.
*/
@CompileStatic
class PointAnalyzer {
static Result analyzePoint(RawNMPoint point, double t0 = 0, int loChannel = 0, int upChannel = 4000) {
int totalN = 0
double totalT = 0;
NMEvent lastEvent = point.events[0];
for (int i = 1; i < point.events.size(); i++) {
NMEvent event = point.events[i];
double t = event.time - lastEvent.time;
if (t >= t0 && event.chanel <= upChannel && event.chanel >= loChannel) {
totalN++
totalT += t
}
lastEvent = event
}
double cr = 1d/(totalT/totalN - t0);
return new Result(cr: cr, crErr: cr / Math.sqrt(totalN), num: totalN, t0: t0, loChannel: loChannel, upChannel: upChannel)
}
static class Result {
double cr;
double crErr;
long num;
double t0;
int loChannel;
int upChannel;
}
}

View File

@ -8,7 +8,7 @@ package inr.numass.scripts
import hep.dataforge.grind.Grind import hep.dataforge.grind.Grind
import hep.dataforge.tables.DataPoint import hep.dataforge.tables.DataPoint
import inr.numass.data.NMPoint import inr.numass.data.NumassPointImpl
import inr.numass.data.RawNMPoint import inr.numass.data.RawNMPoint
import inr.numass.storage.NumassDataLoader import inr.numass.storage.NumassDataLoader
import inr.numass.utils.NMEventGeneratorWithPulser import inr.numass.utils.NMEventGeneratorWithPulser
@ -43,18 +43,18 @@ def data = NumassDataLoader.fromLocalDir(null, dataDir).getNMPoints()
//) //)
//Simulation process //Simulation process
Map<String, List<NMPoint>> res = [:] Map<String, List<NumassPointImpl>> res = [:]
List<NMPoint> generated = new ArrayList<>(); List<NumassPointImpl> generated = new ArrayList<>();
List<NMPoint> registered = new ArrayList<>(); List<NumassPointImpl> registered = new ArrayList<>();
List<NMPoint> firstIteration = new ArrayList<>(); List<NumassPointImpl> firstIteration = new ArrayList<>();
List<NMPoint> secondIteration = new ArrayList<>(); List<NumassPointImpl> secondIteration = new ArrayList<>();
List<NMPoint> pileup = new ArrayList<>(); List<NumassPointImpl> pileup = new ArrayList<>();
lowerChannel = 400; lowerChannel = 400;
upperChannel = 1800; upperChannel = 1800;
PileUpSimulator buildSimulator(NMPoint point, double cr, NMPoint reference = null, boolean extrapolate = true, double scale = 1d) { PileUpSimulator buildSimulator(NumassPointImpl point, double cr, NumassPointImpl reference = null, boolean extrapolate = true, double scale = 1d) {
def cfg = Grind.buildMeta(cr: cr) { def cfg = Grind.buildMeta(cr: cr) {
pulser(mean: 3450, sigma: 86.45, freq: 66.43) pulser(mean: 3450, sigma: 86.45, freq: 66.43)
} }
@ -88,7 +88,7 @@ PileUpSimulator buildSimulator(NMPoint point, double cr, NMPoint reference = nul
return new PileUpSimulator(point.length * scale, rnd, generator).withUset(point.voltage).generate(); return new PileUpSimulator(point.length * scale, rnd, generator).withUset(point.voltage).generate();
} }
double adjustCountRate(PileUpSimulator simulator, NMPoint point) { double adjustCountRate(PileUpSimulator simulator, NumassPointImpl point) {
double generatedInChannel = simulator.generated().getCountInWindow(lowerChannel, upperChannel); double generatedInChannel = simulator.generated().getCountInWindow(lowerChannel, upperChannel);
double registeredInChannel = simulator.registered().getCountInWindow(lowerChannel, upperChannel); double registeredInChannel = simulator.registered().getCountInWindow(lowerChannel, upperChannel);
return (generatedInChannel / registeredInChannel) * (point.getCountInWindow(lowerChannel, upperChannel) / point.getLength()); return (generatedInChannel / registeredInChannel) * (point.getCountInWindow(lowerChannel, upperChannel) / point.getLength());
@ -100,7 +100,7 @@ data.forEach { point ->
PileUpSimulator simulator = buildSimulator(point, cr); PileUpSimulator simulator = buildSimulator(point, cr);
//second iteration to exclude pileup overlap //second iteration to exclude pileup overlap
NMPoint pileupPoint = simulator.pileup(); NumassPointImpl pileupPoint = simulator.pileup();
firstIteration.add(simulator.registered()); firstIteration.add(simulator.registered());
//updating count rate //updating count rate

View File

@ -0,0 +1,49 @@
package inr.numass.scripts
import hep.dataforge.context.Context
import hep.dataforge.context.Global
import hep.dataforge.grind.GrindShell
import hep.dataforge.grind.helpers.PlotHelper
import hep.dataforge.plots.fx.FXPlotManager
import hep.dataforge.tables.MapPoint
import inr.numass.NumassPlugin
import inr.numass.data.PointAnalyzer
import inr.numass.data.RawNMPoint
import inr.numass.storage.NumassStorage
import inr.numass.storage.NumassStorageFactory
/**
* Created by darksnake on 27-Jun-17.
*/
Context ctx = Global.instance()
ctx.pluginManager().load(FXPlotManager)
ctx.pluginManager().load(NumassPlugin.class)
GrindShell shell = new GrindShell(ctx)
shell.eval {
PlotHelper plot = plots
File rootDir = new File("D:\\Work\\Numass\\data\\2017_05\\Fill_1")
NumassStorage storage = NumassStorageFactory.buildLocal(rootDir);
def hv = 15000;
def point = storage.provide("loader::set_2/rawPoint::$hv", RawNMPoint.class).get();
def t0 = (1..150).collect { 5.5e-6 + 2e-7 * it }
def plotPoints = t0.collect {
def result = PointAnalyzer.analyzePoint(point, it,500,3100)
MapPoint.fromMap("x.value": it, "y.value": result.cr, "y.err": result.crErr);
}
//def cr = t0.collect { PointAnalyzer.analyzePoint(point, it).cr }
plot.plot(plotPoints, ["name": hv])
plot.plot(title: "dead time", from: 5.5e-6, to: 2e-5) { point.cr * 1d / (1d - 6.55e-6 * point.cr) }
storage.close()
}

View File

@ -9,9 +9,9 @@ package inr.numass.scripts
import hep.dataforge.io.ColumnedDataWriter import hep.dataforge.io.ColumnedDataWriter
import hep.dataforge.storage.commons.StorageUtils import hep.dataforge.storage.commons.StorageUtils
import hep.dataforge.tables.Table import hep.dataforge.tables.Table
import inr.numass.data.NMPoint
import inr.numass.data.NumassData import inr.numass.data.NumassData
import inr.numass.data.NumassDataUtils import inr.numass.data.NumassDataUtils
import inr.numass.data.NumassPointImpl
import inr.numass.storage.NumassStorage import inr.numass.storage.NumassStorage
import inr.numass.storage.NumassStorageFactory import inr.numass.storage.NumassStorageFactory
import inr.numass.utils.UnderflowCorrection import inr.numass.utils.UnderflowCorrection
@ -23,7 +23,7 @@ File rootDir = new File("D:\\Work\\Numass\\data\\2017_05\\Fill_1")
NumassStorage storage = NumassStorageFactory.buildLocal(rootDir); NumassStorage storage = NumassStorageFactory.buildLocal(rootDir);
Collection<NMPoint> data = NumassDataUtils.joinSpectra( Collection<NumassPointImpl> data = NumassDataUtils.joinSpectra(
StorageUtils.loaderStream(storage) StorageUtils.loaderStream(storage)
.filter { it.key.matches("set_.{1,3}") } .filter { it.key.matches("set_.{1,3}") }
.map { .map {
@ -55,8 +55,8 @@ data = NumassDataUtils.substractReferencePoint(data, 18600d);
// } // }
//} //}
def printPoint(Iterable<NMPoint> data, List<Double> us, int binning = 20, normalize = true) { def printPoint(Iterable<NumassPointImpl> data, List<Double> us, int binning = 20, normalize = true) {
List<NMPoint> points = data.findAll { it.voltage in us }.sort { it.voltage } List<NumassPointImpl> points = data.findAll { it.voltage in us }.sort { it.voltage }
Map spectra = points.first().getMap(binning, normalize).collectEntries { key, value -> Map spectra = points.first().getMap(binning, normalize).collectEntries { key, value ->
[key, [value]] [key, [value]]

View File

@ -20,8 +20,7 @@ import hep.dataforge.data.binary.Binary;
import hep.dataforge.io.BasicIOManager; import hep.dataforge.io.BasicIOManager;
import hep.dataforge.meta.Meta; import hep.dataforge.meta.Meta;
import hep.dataforge.names.Name; import hep.dataforge.names.Name;
import inr.numass.data.NumassDataReader; import inr.numass.data.LegacyDataReader;
import inr.numass.data.NumassPawReader;
import inr.numass.data.RawNMFile; import inr.numass.data.RawNMFile;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.output.TeeOutputStream; import org.apache.commons.io.output.TeeOutputStream;
@ -40,7 +39,7 @@ public class NumassIO extends BasicIOManager {
public static final String NUMASS_OUTPUT_CONTEXT_KEY = "numass.outputDir"; public static final String NUMASS_OUTPUT_CONTEXT_KEY = "numass.outputDir";
public static RawNMFile readAsDat(Binary source, Meta config) throws IOException { public static RawNMFile readAsDat(Binary source, Meta config) throws IOException {
return new NumassDataReader(source, config).read(); return new LegacyDataReader(source, config).read();
} }
// private File getOutputDir() { // private File getOutputDir() {
@ -53,18 +52,15 @@ public class NumassIO extends BasicIOManager {
// //
// } // }
public static RawNMFile readAsPaw(Binary source, Meta config) throws IOException { // public static RawNMFile readAsPaw(Binary source, Meta config) throws IOException {
return new NumassPawReader().readPaw(source, config.getString(FileDataFactory.FILE_NAME_KEY)); // return new NumassPawReader().readPaw(source, config.getString(FileDataFactory.FILE_NAME_KEY));
} // }
public static RawNMFile getNumassData(Binary binary, Meta config) { public static RawNMFile getNumassData(Binary binary, Meta config) {
try { try {
RawNMFile dataFile; RawNMFile dataFile;
String extension = FilenameUtils.getExtension(config.getString(FileDataFactory.FILE_NAME_KEY)).toLowerCase(); String extension = FilenameUtils.getExtension(config.getString(FileDataFactory.FILE_NAME_KEY)).toLowerCase();
switch (extension) { switch (extension) {
case "paw":
dataFile = readAsPaw(binary, config);
break;
case "dat": case "dat":
dataFile = readAsDat(binary, config); dataFile = readAsDat(binary, config);
break; break;

View File

@ -53,7 +53,7 @@ public class DebunchAction extends OneToOneAction<RawNMFile, RawNMFile> {
RawNMFile res = new RawNMFile(source.getName(), source.getHead()); RawNMFile res = new RawNMFile(source.getName(), source.getHead());
source.getData().stream().map((point) -> { source.getData().stream().map((point) -> {
double cr = point.selectChanels(lower, upper).getCR(); double cr = point.selectChanels(lower, upper).getCr();
if (cr < maxCR) { if (cr < maxCR) {
DebunchReport report = new FrameAnalizer(rejectionprob, framelength, lower, upper).debunchPoint(point); DebunchReport report = new FrameAnalizer(rejectionprob, framelength, lower, upper).debunchPoint(point);

View File

@ -4,9 +4,9 @@ import hep.dataforge.actions.ManyToOneAction;
import hep.dataforge.context.Context; import hep.dataforge.context.Context;
import hep.dataforge.description.TypedActionDef; import hep.dataforge.description.TypedActionDef;
import hep.dataforge.meta.Laminate; import hep.dataforge.meta.Laminate;
import inr.numass.data.NMPoint;
import inr.numass.data.NumassData; import inr.numass.data.NumassData;
import inr.numass.data.NumassPoint; import inr.numass.data.NumassPoint;
import inr.numass.data.NumassPointImpl;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
@ -29,7 +29,7 @@ public class JoinNumassDataAction extends ManyToOneAction<NumassData, NumassData
if (p1.getVoltage() != p2.getVoltage()) { 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 NumassPointImpl(
(p1.getVoltage() + p2.getVoltage()) / 2, (p1.getVoltage() + p2.getVoltage()) / 2,
p1.getStartTime(), p1.getStartTime(),
p1.getLength() + p2.getLength(), p1.getLength() + p2.getLength(),

View File

@ -204,7 +204,7 @@ public class PrepareDataAction extends OneToOneAction<NumassData, Table> {
double framelength = meta.getDouble("framelength", 1); double framelength = meta.getDouble("framelength", 1);
double maxCR = meta.getDouble("maxcr", 500d); double maxCR = meta.getDouble("maxcr", 500d);
double cr = point.selectChanels(lower, upper).getCR(); double cr = point.selectChanels(lower, upper).getCr();
if (cr < maxCR) { if (cr < maxCR) {
DebunchReport report = new FrameAnalizer(rejectionprob, framelength, lower, upper).debunchPoint(point); DebunchReport report = new FrameAnalizer(rejectionprob, framelength, lower, upper).debunchPoint(point);
return PointBuilders.readRawPoint(report.getPoint()); return PointBuilders.readRawPoint(report.getPoint());

View File

@ -1,60 +0,0 @@
/*
* Copyright 2015 Alexander Nozik.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package inr.numass.data;
import hep.dataforge.data.binary.Binary;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Locale;
import java.util.Scanner;
/**
*
* @author Darksnake
*/
public class NumassPawReader {
public RawNMFile readPaw(Binary file, String name) throws IOException{
Locale.setDefault(Locale.US);
return readPaw(file.getStream(), name);
}
public RawNMFile readPaw(String filePath) throws FileNotFoundException{
return readPaw(new FileInputStream(filePath), filePath);
}
private RawNMFile readPaw(InputStream stream, String fileName) {
Scanner s = new Scanner(stream);
RawNMFile result = new RawNMFile(fileName);
while (s.hasNext()) {
long eventNum = s.nextLong();
double time = s.nextDouble();
short chanel = s.nextShort();
short timeTotal = s.nextShort();
double U = s.nextDouble();
// NumassEvent event = new NumassEvent(chanel, time);
result.putEvent(U, chanel, time);
}
return result;
}
}

View File

@ -87,7 +87,7 @@ public class FrameAnalizer implements Debuncher {
} }
private DebunchReport debunch(RawNMPoint point, double prob, double frameShift, double frameLength) { private DebunchReport debunch(RawNMPoint point, double prob, double frameShift, double frameLength) {
double cr = point.selectChanels(lowerChanel, upperChanel).getCR(); double cr = point.selectChanels(lowerChanel, upperChanel).getCr();
return debunch(point, cr, prob, frameShift, frameLength); return debunch(point, cr, prob, frameShift, frameLength);
} }

View File

@ -145,7 +145,7 @@ public class NumassPrepareTask extends AbstractTask<Table> {
// double framelength = meta.getDouble("framelength", 1); // double framelength = meta.getDouble("framelength", 1);
// double maxCR = meta.getDouble("maxcr", 500d); // double maxCR = meta.getDouble("maxcr", 500d);
// //
// double cr = point.selectChanels(lower, upper).getCR(); // double cr = point.selectChanels(lower, upper).getCr();
// if (cr < maxCR) { // if (cr < maxCR) {
// DebunchReport report = new FrameAnalizer(rejectionprob, framelength, lower, upper).debunchPoint(point); // DebunchReport report = new FrameAnalizer(rejectionprob, framelength, lower, upper).debunchPoint(point);
// return new NMPoint(report.getPoint()); // return new NMPoint(report.getPoint());

View File

@ -14,6 +14,7 @@ import hep.dataforge.storage.filestorage.FileStorageFactory;
import inr.numass.storage.NumassStorage; import inr.numass.storage.NumassStorage;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader; import java.io.InputStreamReader;
/** /**
@ -32,7 +33,7 @@ public class TestServer {
ServerManager serverManager = context.pluginManager().load(ServerManager.class); ServerManager serverManager = context.pluginManager().load(ServerManager.class);
String path = "D:/temp/test"; File path = new File("/D:/temp/test");
context.getLogger().info("Starting test numass storage servlet in '{}'", path); context.getLogger().info("Starting test numass storage servlet in '{}'", path);
NumassStorage storage = new NumassStorage(context, FileStorageFactory.buildStorageMeta(path, true, true)); NumassStorage storage = new NumassStorage(context, FileStorageFactory.buildStorageMeta(path, true, true));

View File

@ -1,5 +1,5 @@
plugins{ plugins{
id "org.jetbrains.kotlin.jvm" version '1.1.2-5' id "org.jetbrains.kotlin.jvm" version '1.1.3'
id "application" id "application"
} }
@ -27,7 +27,7 @@ dependencies {
compile 'com.jcraft:jsch:0.1.54' compile 'com.jcraft:jsch:0.1.54'
compile 'org.controlsfx:controlsfx:8.40.12' compile 'org.controlsfx:controlsfx:8.40.12'
compile "no.tornado:tornadofx:1.7.5" compile "no.tornado:tornadofx:1.7.8"
} }
apply plugin: 'kotlin' apply plugin: 'kotlin'