Revision of numass data architecture
This commit is contained in:
parent
42e762c421
commit
9395ab5467
@ -18,6 +18,7 @@ package inr.numass.data;
|
|||||||
import hep.dataforge.data.FileDataFactory;
|
import hep.dataforge.data.FileDataFactory;
|
||||||
import hep.dataforge.data.binary.Binary;
|
import hep.dataforge.data.binary.Binary;
|
||||||
import hep.dataforge.meta.Meta;
|
import hep.dataforge.meta.Meta;
|
||||||
|
import inr.numass.data.events.NumassEvent;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@ -97,7 +98,7 @@ public class LegacyDataReader {
|
|||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
|
|
||||||
private NMEvent readEvent(int b, double timeDiv) throws IOException {
|
private NumassEvent readEvent(int b, double timeDiv) throws IOException {
|
||||||
short chanel;
|
short chanel;
|
||||||
long time;
|
long time;
|
||||||
|
|
||||||
@ -125,7 +126,7 @@ public class LegacyDataReader {
|
|||||||
throw new IOException("Event head expected");
|
throw new IOException("Event head expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
return new NMEvent(chanel, time / timeDiv);
|
return new NumassEvent(chanel, time / timeDiv);
|
||||||
}
|
}
|
||||||
|
|
||||||
private RawNMFile readFile(String name) throws IOException {
|
private RawNMFile readFile(String name) throws IOException {
|
||||||
@ -207,7 +208,7 @@ public class LegacyDataReader {
|
|||||||
|
|
||||||
lab = readByte();
|
lab = readByte();
|
||||||
|
|
||||||
List<NMEvent> events = new ArrayList<>();
|
List<NumassEvent> events = new ArrayList<>();
|
||||||
while (lab == 0xBF) {
|
while (lab == 0xBF) {
|
||||||
skip(4);//badHV
|
skip(4);//badHV
|
||||||
lab = readByte();
|
lab = readByte();
|
||||||
|
@ -10,6 +10,7 @@ import java.util.Map;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* A general representation of single voltage measurement.
|
||||||
* Created by darksnake on 13-Apr-17.
|
* Created by darksnake on 13-Apr-17.
|
||||||
*/
|
*/
|
||||||
public interface NumassPoint {
|
public interface NumassPoint {
|
||||||
|
@ -19,6 +19,7 @@ import hep.dataforge.description.ValueDef;
|
|||||||
import hep.dataforge.meta.Meta;
|
import hep.dataforge.meta.Meta;
|
||||||
import hep.dataforge.meta.MetaBuilder;
|
import hep.dataforge.meta.MetaBuilder;
|
||||||
import hep.dataforge.names.NamedMetaHolder;
|
import hep.dataforge.names.NamedMetaHolder;
|
||||||
|
import inr.numass.data.events.NumassEvent;
|
||||||
|
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
@ -61,7 +62,7 @@ public class RawNMFile extends NamedMetaHolder {
|
|||||||
long counter = 0;
|
long counter = 0;
|
||||||
for (RawNMPoint point : this.getData()) {
|
for (RawNMPoint point : this.getData()) {
|
||||||
double U = point.getUread();
|
double U = point.getUread();
|
||||||
for (NMEvent event : point.getEvents()) {
|
for (NumassEvent event : point.getEvents()) {
|
||||||
counter++;
|
counter++;
|
||||||
writer.printf("%d\t%f\t%d\t%.1f\t%.2f%n", counter, event.getTime(), event.getChanel(), point.getLength(), U);
|
writer.printf("%d\t%f\t%d\t%.1f\t%.2f%n", counter, event.getTime(), event.getChanel(), point.getLength(), U);
|
||||||
}
|
}
|
||||||
@ -123,12 +124,12 @@ public class RawNMFile extends NamedMetaHolder {
|
|||||||
// 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 NumassEvent(chanel, time));
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// RawNMPoint newpoint = new RawNMPoint();
|
// RawNMPoint newpoint = new RawNMPoint();
|
||||||
// newpoint.putEvent(new NMEvent(chanel, time));
|
// newpoint.putEvent(new NumassEvent(chanel, time));
|
||||||
// this.putPoint(newpoint);
|
// this.putPoint(newpoint);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package inr.numass.data;
|
package inr.numass.data;
|
||||||
|
|
||||||
|
import inr.numass.data.events.NumassEvent;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -30,27 +32,27 @@ public class RawNMPoint {
|
|||||||
public static int MAX_CHANEL = 4095;
|
public static int MAX_CHANEL = 4095;
|
||||||
|
|
||||||
private Instant startTime;
|
private Instant startTime;
|
||||||
private final List<NMEvent> events;
|
private final List<NumassEvent> events;
|
||||||
private double length;
|
private double length;
|
||||||
private double uread;
|
private double uread;
|
||||||
|
|
||||||
private double uset;
|
private double uset;
|
||||||
|
|
||||||
public RawNMPoint(double U, List<NMEvent> events, double t) {
|
public RawNMPoint(double U, List<NumassEvent> events, double t) {
|
||||||
this.uset = U;
|
this.uset = U;
|
||||||
this.uread = U;
|
this.uread = U;
|
||||||
this.events = events;
|
this.events = events;
|
||||||
this.length = t;
|
this.length = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RawNMPoint(double Uset, double Uread, List<NMEvent> events, double t) {
|
public RawNMPoint(double Uset, double Uread, List<NumassEvent> events, double t) {
|
||||||
this.uset = Uset;
|
this.uset = Uset;
|
||||||
this.uread = Uread;
|
this.uread = Uread;
|
||||||
this.events = events;
|
this.events = events;
|
||||||
this.length = t;
|
this.length = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RawNMPoint(double uset, double uread, List<NMEvent> events, double t, Instant absouteTime) {
|
public RawNMPoint(double uset, double uread, List<NumassEvent> events, double t, Instant absouteTime) {
|
||||||
this.uset = uset;
|
this.uset = uset;
|
||||||
this.uread = uread;
|
this.uread = uread;
|
||||||
this.length = t;
|
this.length = t;
|
||||||
@ -67,7 +69,7 @@ public class RawNMPoint {
|
|||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
// public RawNMPoint clone() {
|
// public RawNMPoint clone() {
|
||||||
// ArrayList<NMEvent> newevents = new ArrayList<>();
|
// ArrayList<NumassEvent> newevents = new ArrayList<>();
|
||||||
// newevents.addAll(this.getEvents());
|
// newevents.addAll(this.getEvents());
|
||||||
// return new RawNMPoint(getUset(), getUread(), newevents, getLength());
|
// return new RawNMPoint(getUset(), getUread(), newevents, getLength());
|
||||||
// }
|
// }
|
||||||
@ -87,7 +89,7 @@ public class RawNMPoint {
|
|||||||
/**
|
/**
|
||||||
* @return the events
|
* @return the events
|
||||||
*/
|
*/
|
||||||
public List<NMEvent> getEvents() {
|
public List<NumassEvent> getEvents() {
|
||||||
return events;
|
return events;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,24 +132,24 @@ public class RawNMPoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public RawNMPoint merge(RawNMPoint point) {
|
public RawNMPoint merge(RawNMPoint point) {
|
||||||
List<NMEvent> events = new ArrayList<>(this.events);
|
List<NumassEvent> events = new ArrayList<>(this.events);
|
||||||
for (NMEvent newEvent : point.getEvents()) {
|
for (NumassEvent newEvent : point.getEvents()) {
|
||||||
events.add(new NMEvent(newEvent.getChanel(), newEvent.getTime() + this.getLength()));
|
events.add(new NumassEvent(newEvent.getChanel(), newEvent.getTime() + this.getLength()));
|
||||||
}
|
}
|
||||||
double length = this.length + point.length;
|
double length = this.length + point.length;
|
||||||
double uread = (this.uread + point.uread) / 2;
|
double uread = (this.uread + point.uread) / 2;
|
||||||
return new RawNMPoint(this.uset, uread, events, length, this.startTime);
|
return new RawNMPoint(this.uset, uread, events, length, this.startTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
// void putEvent(NMEvent event) {
|
// void putEvent(NumassEvent 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;
|
||||||
|
|
||||||
List<NMEvent> res = new ArrayList<>();
|
List<NumassEvent> res = new ArrayList<>();
|
||||||
for (NMEvent event : this.getEvents()) {
|
for (NumassEvent event : this.getEvents()) {
|
||||||
if ((event.getChanel() >= from) && (event.getChanel() <= to)) {
|
if ((event.getChanel() >= from) && (event.getChanel() <= to)) {
|
||||||
res.add(event);
|
res.add(event);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
package inr.numass.data.events;
|
||||||
|
|
||||||
|
import hep.dataforge.meta.Meta;
|
||||||
|
import hep.dataforge.tables.Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A general raw data analysis utility. Could have different implementations
|
||||||
|
* Created by darksnake on 06-Jul-17.
|
||||||
|
*/
|
||||||
|
public interface NumassAnalyzer {
|
||||||
|
/**
|
||||||
|
* Caclulate the number of events in given window
|
||||||
|
*
|
||||||
|
* @param block
|
||||||
|
* @param from
|
||||||
|
* @param to
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int getCountInWindow(NumassBlock block, int from, int to);
|
||||||
|
|
||||||
|
default int getMaxChannel() {
|
||||||
|
return 4096;
|
||||||
|
}
|
||||||
|
|
||||||
|
default int getCountTotal(NumassBlock block) {
|
||||||
|
return getCountInWindow(block, 0, getMaxChannel());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Table getSpectrum(Meta config);
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package inr.numass.data.events;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A single continuous measurement block. The block can contain both isolated events and signal frames
|
||||||
|
* <p>
|
||||||
|
* Created by darksnake on 06-Jul-17.
|
||||||
|
*/
|
||||||
|
public interface NumassBlock {
|
||||||
|
/**
|
||||||
|
* The absolute start time of the block
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Instant getStartTime();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The length of the block
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Duration getLength();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stream of isolated events. Could be empty
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Stream<NumassEvent> getEvents();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stream of frames. Could be empty
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Stream<NumassFrame> getFrames();
|
||||||
|
}
|
@ -13,26 +13,21 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package inr.numass.data;
|
package inr.numass.data.events;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* A single numass event with given amplitude ant time.
|
||||||
* @author Darksnake
|
* @author Darksnake
|
||||||
*/
|
*/
|
||||||
public class NMEvent{
|
public class NumassEvent {
|
||||||
protected final short chanel;
|
protected final short chanel;
|
||||||
protected final double time;
|
protected final double time;
|
||||||
|
|
||||||
public NMEvent(short chanel, double time) {
|
public NumassEvent(short chanel, double time) {
|
||||||
this.chanel = chanel;
|
this.chanel = chanel;
|
||||||
this.time = time;
|
this.time = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
|
||||||
// public NMEvent clone() {
|
|
||||||
// return new NMEvent(chanel, time);
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the chanel
|
* @return the chanel
|
||||||
*/
|
*/
|
@ -0,0 +1,50 @@
|
|||||||
|
package inr.numass.data.events;
|
||||||
|
|
||||||
|
import java.nio.ShortBuffer;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The continuous frame of digital detector data
|
||||||
|
* Created by darksnake on 06-Jul-17.
|
||||||
|
*/
|
||||||
|
public class NumassFrame {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The absolute start time of the frame
|
||||||
|
*/
|
||||||
|
private final Instant startTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The buffered signal shape in ticks
|
||||||
|
*/
|
||||||
|
private final ShortBuffer signal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The time interval per tick
|
||||||
|
*/
|
||||||
|
private final Duration tickSize;
|
||||||
|
|
||||||
|
|
||||||
|
public NumassFrame(Instant startTime, Duration tickSize, ShortBuffer signal) {
|
||||||
|
this.startTime = startTime;
|
||||||
|
this.signal = signal;
|
||||||
|
this.tickSize = tickSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Instant getStartTime() {
|
||||||
|
return startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShortBuffer getSignal() {
|
||||||
|
return signal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Duration getTickSize() {
|
||||||
|
return tickSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Duration getLength() {
|
||||||
|
return tickSize.multipliedBy(signal.capacity());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package inr.numass.data.events;
|
||||||
|
|
||||||
|
import hep.dataforge.meta.Metoid;
|
||||||
|
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by darksnake on 06-Jul-17.
|
||||||
|
*/
|
||||||
|
public interface NumassPoint extends Metoid {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Stream<NumassBlock> getBlocks();
|
||||||
|
}
|
@ -30,7 +30,11 @@ import hep.dataforge.storage.filestorage.FileEnvelope;
|
|||||||
import hep.dataforge.storage.filestorage.FileStorage;
|
import hep.dataforge.storage.filestorage.FileStorage;
|
||||||
import hep.dataforge.storage.loaders.AbstractLoader;
|
import hep.dataforge.storage.loaders.AbstractLoader;
|
||||||
import hep.dataforge.tables.Table;
|
import hep.dataforge.tables.Table;
|
||||||
import inr.numass.data.*;
|
import inr.numass.data.NumassData;
|
||||||
|
import inr.numass.data.NumassPoint;
|
||||||
|
import inr.numass.data.PointBuilders;
|
||||||
|
import inr.numass.data.RawNMPoint;
|
||||||
|
import inr.numass.data.events.NumassEvent;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -164,7 +168,7 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private synchronized RawNMPoint readRawPoint(Envelope envelope) {
|
private synchronized RawNMPoint readRawPoint(Envelope envelope) {
|
||||||
List<NMEvent> events = new ArrayList<>();
|
List<NumassEvent> events = new ArrayList<>();
|
||||||
|
|
||||||
double timeCoef = envelope.meta().getDouble("time_coeff", 50);
|
double timeCoef = envelope.meta().getDouble("time_coeff", 50);
|
||||||
try (ReadableByteChannel inChannel = envelope.getData().getChannel()) {
|
try (ReadableByteChannel inChannel = envelope.getData().getChannel()) {
|
||||||
@ -176,7 +180,7 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
|
|||||||
short channel = (short) Short.toUnsignedInt(buffer.getShort());
|
short channel = (short) Short.toUnsignedInt(buffer.getShort());
|
||||||
long time = Integer.toUnsignedLong(buffer.getInt());
|
long time = Integer.toUnsignedLong(buffer.getInt());
|
||||||
byte status = buffer.get(); // status is ignored
|
byte status = buffer.get(); // status is ignored
|
||||||
NMEvent event = new NMEvent(channel, (double) time * timeCoef * 1e-9);
|
NumassEvent event = new NumassEvent(channel, (double) time * timeCoef * 1e-9);
|
||||||
events.add(event);
|
events.add(event);
|
||||||
}
|
}
|
||||||
buffer.clear(); // do something with the data and clear/compact it.
|
buffer.clear(); // do something with the data and clear/compact it.
|
||||||
|
@ -3,6 +3,7 @@ package inr.numass.data
|
|||||||
import groovy.transform.CompileStatic
|
import groovy.transform.CompileStatic
|
||||||
import hep.dataforge.maths.histogram.Histogram
|
import hep.dataforge.maths.histogram.Histogram
|
||||||
import hep.dataforge.maths.histogram.UnivariateHistogram
|
import hep.dataforge.maths.histogram.UnivariateHistogram
|
||||||
|
import inr.numass.data.events.NumassEvent
|
||||||
|
|
||||||
import java.util.stream.DoubleStream
|
import java.util.stream.DoubleStream
|
||||||
|
|
||||||
@ -15,10 +16,10 @@ class PointAnalyzer {
|
|||||||
static Result analyzePoint(RawNMPoint point, double t0 = 0, int loChannel = 0, int upChannel = 4000) {
|
static Result analyzePoint(RawNMPoint point, double t0 = 0, int loChannel = 0, int upChannel = 4000) {
|
||||||
int totalN = 0
|
int totalN = 0
|
||||||
double totalT = 0;
|
double totalT = 0;
|
||||||
NMEvent lastEvent = point.events[0];
|
NumassEvent lastEvent = point.events[0];
|
||||||
|
|
||||||
for (int i = 1; i < point.events.size(); i++) {
|
for (int i = 1; i < point.events.size(); i++) {
|
||||||
NMEvent event = point.events[i];
|
NumassEvent event = point.events[i];
|
||||||
double t = event.time - lastEvent.time;
|
double t = event.time - lastEvent.time;
|
||||||
if (t < 0) {
|
if (t < 0) {
|
||||||
lastEvent = event
|
lastEvent = event
|
||||||
@ -32,12 +33,14 @@ class PointAnalyzer {
|
|||||||
return new Result(cr: cr, crErr: cr / Math.sqrt(totalN), num: totalN, t0: t0, loChannel: loChannel, upChannel: upChannel)
|
return new Result(cr: cr, crErr: cr / Math.sqrt(totalN), num: totalN, t0: t0, loChannel: loChannel, upChannel: upChannel)
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DoubleStream timeChain(RawNMPoint point, int loChannel = 0, int upChannel = 4000) {
|
static DoubleStream timeChain(int loChannel = 0, int upChannel = 4000, RawNMPoint... points) {
|
||||||
|
DoubleStream stream = DoubleStream.empty();
|
||||||
|
for(RawNMPoint point: points){
|
||||||
List<Double> ts = new ArrayList<>();
|
List<Double> ts = new ArrayList<>();
|
||||||
NMEvent lastEvent = point.events[0];
|
NumassEvent lastEvent = point.events[0];
|
||||||
|
|
||||||
for (int i = 1; i < point.events.size(); i++) {
|
for (int i = 1; i < point.events.size(); i++) {
|
||||||
NMEvent event = point.events[i];
|
NumassEvent event = point.events[i];
|
||||||
double t = event.time - lastEvent.time;
|
double t = event.time - lastEvent.time;
|
||||||
if (t < 0) {
|
if (t < 0) {
|
||||||
lastEvent = event
|
lastEvent = event
|
||||||
@ -46,7 +49,9 @@ class PointAnalyzer {
|
|||||||
lastEvent = event
|
lastEvent = event
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ts.stream().mapToDouble { it }
|
stream = DoubleStream.concat(stream,ts.stream().mapToDouble{it});
|
||||||
|
}
|
||||||
|
return stream
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,12 +64,16 @@ class PointAnalyzer {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static long count(RawNMPoint point, double t1, double t2, int loChannel = 0, int upChannel = 4000) {
|
static long count(RawNMPoint point, double t1, double t2, int loChannel = 0, int upChannel = 4000) {
|
||||||
return timeChain(point, loChannel, upChannel).filter { it > t1 && it < t2 }.count();
|
return timeChain(loChannel, upChannel, point).filter { it > t1 && it < t2 }.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Histogram histogram(RawNMPoint point, int loChannel = 0, int upChannel = 4000, double binSize = 1e-6d, int binNum = 500) {
|
static Histogram histogram(RawNMPoint point, int loChannel = 0, int upChannel = 4000, double binSize = 1e-6d, int binNum = 500) {
|
||||||
return UnivariateHistogram.buildUniform(0d, binSize*binNum, binSize).fill(timeChain(point, loChannel, upChannel))
|
return UnivariateHistogram.buildUniform(0d, binSize*binNum, binSize).fill(timeChain(loChannel, upChannel, point))
|
||||||
|
}
|
||||||
|
|
||||||
|
static Histogram histogram(DoubleStream stream, double binSize = 1e-6d, int binNum = 500) {
|
||||||
|
return UnivariateHistogram.buildUniform(0d, binSize*binNum, binSize).fill(stream)
|
||||||
}
|
}
|
||||||
|
|
||||||
static class Result {
|
static class Result {
|
||||||
|
@ -0,0 +1,57 @@
|
|||||||
|
package inr.numass.scripts.times
|
||||||
|
|
||||||
|
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 inr.numass.NumassPlugin
|
||||||
|
import inr.numass.data.PointAnalyzer
|
||||||
|
import inr.numass.data.RawNMPoint
|
||||||
|
import inr.numass.storage.NumassDataLoader
|
||||||
|
import inr.numass.storage.NumassStorage
|
||||||
|
import inr.numass.storage.NumassStorageFactory
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by darksnake on 06-Jul-17.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
Context ctx = Global.instance()
|
||||||
|
ctx.pluginManager().load(FXPlotManager)
|
||||||
|
ctx.pluginManager().load(NumassPlugin.class)
|
||||||
|
|
||||||
|
new GrindShell(ctx).eval {
|
||||||
|
PlotHelper plot = plots
|
||||||
|
File rootDir = new File("D:\\Work\\Numass\\data\\2017_05\\Fill_2")
|
||||||
|
|
||||||
|
NumassStorage storage = NumassStorageFactory.buildLocal(rootDir);
|
||||||
|
|
||||||
|
def pattern = "set_.{1,2}"
|
||||||
|
|
||||||
|
List<NumassDataLoader> loaders = storage.loaders().findAll{it.name.matches(pattern)}.collect{it as NumassDataLoader}
|
||||||
|
|
||||||
|
println "Found ${loaders.size()} loaders matching pattern"
|
||||||
|
|
||||||
|
def hv = 16000.toString();
|
||||||
|
List<RawNMPoint> points = loaders.collect { loader -> loader.optRawPoint(hv).get()}
|
||||||
|
|
||||||
|
def loChannel = 400;
|
||||||
|
def upChannel = 800;
|
||||||
|
|
||||||
|
def chain = PointAnalyzer.timeChain(loChannel,upChannel, points as RawNMPoint[])
|
||||||
|
|
||||||
|
def histogram = PointAnalyzer.histogram(chain, 5e-6,500).asTable();
|
||||||
|
|
||||||
|
println "finished histogram calculation..."
|
||||||
|
|
||||||
|
plot.configure("histogram") {
|
||||||
|
yAxis(type: "log")
|
||||||
|
}
|
||||||
|
|
||||||
|
plot.plot(name: hv, frame: "histogram", showLine: true, showSymbol: false, showErrors: false, connectionType: "step", histogram, {
|
||||||
|
adapter("x.value": "x", "y.value": "count")
|
||||||
|
})
|
||||||
|
|
||||||
|
storage.close()
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package inr.numass.scripts
|
package inr.numass.scripts.times
|
||||||
|
|
||||||
import hep.dataforge.context.Context
|
import hep.dataforge.context.Context
|
||||||
import hep.dataforge.context.Global
|
import hep.dataforge.context.Global
|
||||||
@ -25,15 +25,15 @@ GrindShell shell = new GrindShell(ctx)
|
|||||||
|
|
||||||
shell.eval {
|
shell.eval {
|
||||||
PlotHelper plot = plots
|
PlotHelper plot = plots
|
||||||
File rootDir = new File("D:\\Work\\Numass\\data\\2017_05\\Fill_1C")
|
File rootDir = new File("D:\\Work\\Numass\\data\\2017_05\\Fill_1")
|
||||||
|
|
||||||
NumassStorage storage = NumassStorageFactory.buildLocal(rootDir);
|
NumassStorage storage = NumassStorageFactory.buildLocal(rootDir);
|
||||||
|
|
||||||
def set = "set_6"
|
def set = "set_1"
|
||||||
def hv = 15000;
|
def hv = 18400;
|
||||||
|
|
||||||
def loChannel = 3000;
|
def loChannel = 400;
|
||||||
def upChannel = 3600;
|
def upChannel = 2000;
|
||||||
|
|
||||||
def point = storage.provide("loader::$set/rawPoint::$hv", RawNMPoint.class).get();
|
def point = storage.provide("loader::$set/rawPoint::$hv", RawNMPoint.class).get();
|
||||||
|
|
@ -15,8 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package inr.numass.debunch;
|
package inr.numass.debunch;
|
||||||
|
|
||||||
import inr.numass.data.NMEvent;
|
|
||||||
import inr.numass.data.RawNMPoint;
|
import inr.numass.data.RawNMPoint;
|
||||||
|
import inr.numass.data.events.NumassEvent;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -40,11 +40,11 @@ class DebunchData {
|
|||||||
* @param to
|
* @param to
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private static List<NMEvent> removeFrame(List<NMEvent> events, Frame frame) {
|
private static List<NumassEvent> removeFrame(List<NumassEvent> events, Frame frame) {
|
||||||
List<NMEvent> res = new ArrayList<>();
|
List<NumassEvent> res = new ArrayList<>();
|
||||||
for (NMEvent event : events) {
|
for (NumassEvent event : events) {
|
||||||
if (event.getTime() >= frame.getEnd()) {
|
if (event.getTime() >= frame.getEnd()) {
|
||||||
res.add(new NMEvent(event.getChanel(), event.getTime() - frame.length()));
|
res.add(new NumassEvent(event.getChanel(), event.getTime() - frame.length()));
|
||||||
} else if (event.getTime() <= frame.getBegin()) {
|
} else if (event.getTime() <= frame.getBegin()) {
|
||||||
res.add(event);
|
res.add(event);
|
||||||
}
|
}
|
||||||
@ -53,7 +53,7 @@ class DebunchData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final List<Frame> bunches = new ArrayList<>();
|
private final List<Frame> bunches = new ArrayList<>();
|
||||||
private final List<NMEvent> events;
|
private final List<NumassEvent> events;
|
||||||
private final double length;
|
private final double length;
|
||||||
|
|
||||||
public DebunchData(RawNMPoint point) {
|
public DebunchData(RawNMPoint point) {
|
||||||
@ -71,7 +71,7 @@ class DebunchData {
|
|||||||
end = this.getLength();
|
end = this.getLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<NMEvent> sum = new ArrayList<>();
|
ArrayList<NumassEvent> sum = new ArrayList<>();
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while ((i < this.size()) && (events.get(i).getTime() < start)) {
|
while ((i < this.size()) && (events.get(i).getTime() < start)) {
|
||||||
@ -146,8 +146,8 @@ class DebunchData {
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public List<NMEvent> getDebunchedEvents() {
|
public List<NumassEvent> getDebunchedEvents() {
|
||||||
List<NMEvent> res = getEvents();
|
List<NumassEvent> res = getEvents();
|
||||||
for (Frame frame : getBunches()) {
|
for (Frame frame : getBunches()) {
|
||||||
res = removeFrame(res, frame);
|
res = removeFrame(res, frame);
|
||||||
}
|
}
|
||||||
@ -171,7 +171,7 @@ class DebunchData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<NMEvent> getEvents() {
|
public List<NumassEvent> getEvents() {
|
||||||
return events;
|
return events;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,10 +196,10 @@ class DebunchData {
|
|||||||
return this.getEvents().size();
|
return this.getEvents().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class EventComparator implements Comparator<NMEvent> {
|
private static class EventComparator implements Comparator<NumassEvent> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(NMEvent o1, NMEvent o2) {
|
public int compare(NumassEvent o1, NumassEvent o2) {
|
||||||
return (int) Math.signum(o1.getTime() - o2.getTime());
|
return (int) Math.signum(o1.getTime() - o2.getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,15 +15,15 @@
|
|||||||
*/
|
*/
|
||||||
package inr.numass.debunch;
|
package inr.numass.debunch;
|
||||||
|
|
||||||
import inr.numass.data.NMEvent;
|
import inr.numass.data.events.NumassEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Darksnake
|
* @author Darksnake
|
||||||
*/
|
*/
|
||||||
public class DebunchEvent extends NMEvent {
|
public class DebunchEvent extends NumassEvent {
|
||||||
|
|
||||||
public static double getEventWeight(NMEvent event) {
|
public static double getEventWeight(NumassEvent event) {
|
||||||
if (event instanceof DebunchEvent) {
|
if (event instanceof DebunchEvent) {
|
||||||
return ((DebunchEvent) event).getWeight();
|
return ((DebunchEvent) event).getWeight();
|
||||||
} else {
|
} else {
|
||||||
@ -39,7 +39,7 @@ public class DebunchEvent extends NMEvent {
|
|||||||
*/
|
*/
|
||||||
private double weight;
|
private double weight;
|
||||||
|
|
||||||
public DebunchEvent(NMEvent event, double weight) {
|
public DebunchEvent(NumassEvent event, double weight) {
|
||||||
super(event.getChanel(), event.getTime());
|
super(event.getChanel(), event.getTime());
|
||||||
this.weight = weight;
|
this.weight = weight;
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package inr.numass.debunch;
|
package inr.numass.debunch;
|
||||||
|
|
||||||
import inr.numass.data.NMEvent;
|
|
||||||
import inr.numass.data.RawNMPoint;
|
import inr.numass.data.RawNMPoint;
|
||||||
|
import inr.numass.data.events.NumassEvent;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ public interface DebunchReport {
|
|||||||
RawNMPoint getPoint();
|
RawNMPoint getPoint();
|
||||||
|
|
||||||
List<Frame> getBunches();
|
List<Frame> getBunches();
|
||||||
List<NMEvent> getBunchEvents();
|
List<NumassEvent> getBunchEvents();
|
||||||
|
|
||||||
double eventsFiltred();
|
double eventsFiltred();
|
||||||
double timeFiltred();
|
double timeFiltred();
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package inr.numass.debunch;
|
package inr.numass.debunch;
|
||||||
|
|
||||||
import inr.numass.data.NMEvent;
|
|
||||||
import inr.numass.data.RawNMPoint;
|
import inr.numass.data.RawNMPoint;
|
||||||
|
import inr.numass.data.events.NumassEvent;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -52,8 +52,8 @@ public class DebunchReportImpl implements DebunchReport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<NMEvent> getBunchEvents() {
|
public List<NumassEvent> getBunchEvents() {
|
||||||
List<NMEvent> res = new ArrayList<>();
|
List<NumassEvent> res = new ArrayList<>();
|
||||||
for (Frame interval : getBunches()) {
|
for (Frame interval : getBunches()) {
|
||||||
res.addAll(interval.getEvents());
|
res.addAll(interval.getEvents());
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package inr.numass.debunch;
|
package inr.numass.debunch;
|
||||||
|
|
||||||
import inr.numass.data.NMEvent;
|
import inr.numass.data.events.NumassEvent;
|
||||||
import org.apache.commons.math3.distribution.PoissonDistribution;
|
import org.apache.commons.math3.distribution.PoissonDistribution;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -29,10 +29,10 @@ public class Frame {
|
|||||||
|
|
||||||
private final double begin;
|
private final double begin;
|
||||||
private final double end;
|
private final double end;
|
||||||
private List<NMEvent> events;
|
private List<NumassEvent> events;
|
||||||
private final int eventsCount;
|
private final int eventsCount;
|
||||||
|
|
||||||
public Frame(double begin, double end, List<NMEvent> events) {
|
public Frame(double begin, double end, List<NumassEvent> events) {
|
||||||
assert end > begin;
|
assert end > begin;
|
||||||
this.begin = begin;
|
this.begin = begin;
|
||||||
this.end = end;
|
this.end = end;
|
||||||
@ -82,7 +82,7 @@ public class Frame {
|
|||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<NMEvent> getEvents() {
|
public List<NumassEvent> getEvents() {
|
||||||
if(events!=null)
|
if(events!=null)
|
||||||
return events;
|
return events;
|
||||||
else
|
else
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package inr.numass.utils;
|
package inr.numass.utils;
|
||||||
|
|
||||||
import inr.numass.data.NMEvent;
|
|
||||||
import inr.numass.data.RawNMPoint;
|
import inr.numass.data.RawNMPoint;
|
||||||
|
import inr.numass.data.events.NumassEvent;
|
||||||
import org.apache.commons.math3.random.MersenneTwister;
|
import org.apache.commons.math3.random.MersenneTwister;
|
||||||
import org.apache.commons.math3.random.RandomGenerator;
|
import org.apache.commons.math3.random.RandomGenerator;
|
||||||
import org.apache.commons.math3.random.SynchronizedRandomGenerator;
|
import org.apache.commons.math3.random.SynchronizedRandomGenerator;
|
||||||
@ -52,12 +52,12 @@ public class BunchGenerator {
|
|||||||
expGen = new ExpGenerator(gen);
|
expGen = new ExpGenerator(gen);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<NMEvent> generate(double dist, double length, double timeShift, boolean isBunch) {
|
public ArrayList<NumassEvent> generate(double dist, double length, double timeShift, boolean isBunch) {
|
||||||
ArrayList<NMEvent> res = new ArrayList<>();
|
ArrayList<NumassEvent> res = new ArrayList<>();
|
||||||
ArrayList<Double> events = generateEvents(dist, length);
|
ArrayList<Double> events = generateEvents(dist, length);
|
||||||
for (Double event : events) {
|
for (Double event : events) {
|
||||||
if (event < length) {
|
if (event < length) {
|
||||||
res.add(new NMEvent((short)0,event + timeShift));
|
res.add(new NumassEvent((short)0,event + timeShift));
|
||||||
// if (isBunch) {
|
// if (isBunch) {
|
||||||
// res.add(new DebunchEvent(event + timeShift, 10));
|
// res.add(new DebunchEvent(event + timeShift, 10));
|
||||||
// } else {
|
// } else {
|
||||||
@ -104,16 +104,16 @@ public class BunchGenerator {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<NMEvent> generateNormalEvents(double measurementTime) {
|
public ArrayList<NumassEvent> generateNormalEvents(double measurementTime) {
|
||||||
return generate(1 / cr, measurementTime, 0, false);
|
return generate(1 / cr, measurementTime, 0, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<NMEvent> generateTriangle(double dist, double length, double timeShift, boolean isBunch) {
|
public ArrayList<NumassEvent> generateTriangle(double dist, double length, double timeShift, boolean isBunch) {
|
||||||
ArrayList<NMEvent> res = new ArrayList<>();
|
ArrayList<NumassEvent> res = new ArrayList<>();
|
||||||
ArrayList<Double> events = generateEventsTriangle(dist, length);
|
ArrayList<Double> events = generateEventsTriangle(dist, length);
|
||||||
for (Double event : events) {
|
for (Double event : events) {
|
||||||
if (event < length) {
|
if (event < length) {
|
||||||
res.add(new NMEvent((short)0,event + timeShift));
|
res.add(new NumassEvent((short)0,event + timeShift));
|
||||||
// if (isBunch) {
|
// if (isBunch) {
|
||||||
// res.add(new DebunchEvent(event + timeShift, 10));
|
// res.add(new DebunchEvent(event + timeShift, 10));
|
||||||
// } else {
|
// } else {
|
||||||
@ -131,7 +131,7 @@ public class BunchGenerator {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public RawNMPoint generateWithBunches(double measurementTime) {
|
public RawNMPoint generateWithBunches(double measurementTime) {
|
||||||
ArrayList<NMEvent> res = generateNormalEvents(measurementTime);
|
ArrayList<NumassEvent> res = generateNormalEvents(measurementTime);
|
||||||
ArrayList<Double> bunchList = generateEvents(bunchDist, measurementTime);
|
ArrayList<Double> bunchList = generateEvents(bunchDist, measurementTime);
|
||||||
for (Double bunchPos : bunchList) {
|
for (Double bunchPos : bunchList) {
|
||||||
res.addAll(generate(1 / bunchCr, bunchLength, bunchPos, true));
|
res.addAll(generate(1 / bunchCr, bunchLength, bunchPos, true));
|
||||||
@ -145,7 +145,7 @@ public class BunchGenerator {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public RawNMPoint generateWithRandomBunches(double measurementTime) {
|
public RawNMPoint generateWithRandomBunches(double measurementTime) {
|
||||||
ArrayList<NMEvent> res = generateNormalEvents(measurementTime);
|
ArrayList<NumassEvent> res = generateNormalEvents(measurementTime);
|
||||||
ArrayList<Double> bunchList = generateEvents(bunchDist, measurementTime);
|
ArrayList<Double> bunchList = generateEvents(bunchDist, measurementTime);
|
||||||
for (Double bunchPos : bunchList) {
|
for (Double bunchPos : bunchList) {
|
||||||
double l = expGen.nextSafeGaussian(bunchLength, bunchLength / 3);
|
double l = expGen.nextSafeGaussian(bunchLength, bunchLength / 3);
|
||||||
@ -156,7 +156,7 @@ public class BunchGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public RawNMPoint generateWithTriangleBunches(double measurementTime) {
|
public RawNMPoint generateWithTriangleBunches(double measurementTime) {
|
||||||
ArrayList<NMEvent> res = generateNormalEvents(measurementTime);
|
ArrayList<NumassEvent> res = generateNormalEvents(measurementTime);
|
||||||
ArrayList<Double> bunchList = generateEvents(bunchDist, measurementTime);
|
ArrayList<Double> bunchList = generateEvents(bunchDist, measurementTime);
|
||||||
for (Double bunchPos : bunchList) {
|
for (Double bunchPos : bunchList) {
|
||||||
res.addAll(generateTriangle(1 / bunchCr, bunchLength, bunchPos, true));
|
res.addAll(generateTriangle(1 / bunchCr, bunchLength, bunchPos, true));
|
||||||
|
@ -16,9 +16,9 @@
|
|||||||
package inr.numass.utils;
|
package inr.numass.utils;
|
||||||
|
|
||||||
import hep.dataforge.meta.Meta;
|
import hep.dataforge.meta.Meta;
|
||||||
import inr.numass.data.NMEvent;
|
|
||||||
import inr.numass.data.NumassPoint;
|
import inr.numass.data.NumassPoint;
|
||||||
import inr.numass.data.RawNMPoint;
|
import inr.numass.data.RawNMPoint;
|
||||||
|
import inr.numass.data.events.NumassEvent;
|
||||||
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;
|
||||||
import org.apache.commons.math3.random.EmpiricalDistribution;
|
import org.apache.commons.math3.random.EmpiricalDistribution;
|
||||||
@ -34,12 +34,12 @@ import java.util.function.Supplier;
|
|||||||
*
|
*
|
||||||
* @author Darksnake
|
* @author Darksnake
|
||||||
*/
|
*/
|
||||||
public class NMEventGenerator implements Supplier<NMEvent> {
|
public class NMEventGenerator implements Supplier<NumassEvent> {
|
||||||
|
|
||||||
protected final RandomGenerator rnd;
|
protected final RandomGenerator rnd;
|
||||||
protected double cr;
|
protected double cr;
|
||||||
protected RealDistribution distribution;
|
protected RealDistribution distribution;
|
||||||
protected NMEvent prevEvent;
|
protected NumassEvent prevEvent;
|
||||||
|
|
||||||
public NMEventGenerator(RandomGenerator rnd, double cr) {
|
public NMEventGenerator(RandomGenerator rnd, double cr) {
|
||||||
this.cr = cr;
|
this.cr = cr;
|
||||||
@ -120,7 +120,7 @@ public class NMEventGenerator implements Supplier<NMEvent> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected NMEvent nextEvent(NMEvent prev) {
|
protected NumassEvent nextEvent(NumassEvent prev) {
|
||||||
short chanel;
|
short chanel;
|
||||||
|
|
||||||
if (distribution != null) {
|
if (distribution != null) {
|
||||||
@ -129,12 +129,12 @@ public class NMEventGenerator implements Supplier<NMEvent> {
|
|||||||
chanel = 1600;
|
chanel = 1600;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new NMEvent(chanel, (prev == null ? 0 : prev.getTime()) + nextExpDecay(1d / cr));
|
return new NumassEvent(chanel, (prev == null ? 0 : prev.getTime()) + nextExpDecay(1d / cr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized NMEvent get() {
|
public synchronized NumassEvent get() {
|
||||||
return prevEvent = nextEvent(prevEvent);
|
return prevEvent = nextEvent(prevEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package inr.numass.utils;
|
package inr.numass.utils;
|
||||||
|
|
||||||
import hep.dataforge.meta.Meta;
|
import hep.dataforge.meta.Meta;
|
||||||
import inr.numass.data.NMEvent;
|
import inr.numass.data.events.NumassEvent;
|
||||||
import org.apache.commons.math3.distribution.NormalDistribution;
|
import org.apache.commons.math3.distribution.NormalDistribution;
|
||||||
import org.apache.commons.math3.distribution.RealDistribution;
|
import org.apache.commons.math3.distribution.RealDistribution;
|
||||||
import org.apache.commons.math3.random.RandomGenerator;
|
import org.apache.commons.math3.random.RandomGenerator;
|
||||||
@ -12,8 +12,8 @@ import org.apache.commons.math3.random.RandomGenerator;
|
|||||||
public class NMEventGeneratorWithPulser extends NMEventGenerator {
|
public class NMEventGeneratorWithPulser extends NMEventGenerator {
|
||||||
private RealDistribution pulserChanelDistribution;
|
private RealDistribution pulserChanelDistribution;
|
||||||
private double pulserDist;
|
private double pulserDist;
|
||||||
private NMEvent pulserEvent;
|
private NumassEvent pulserEvent;
|
||||||
private NMEvent nextEvent;
|
private NumassEvent nextEvent;
|
||||||
|
|
||||||
public NMEventGeneratorWithPulser(RandomGenerator rnd, Meta meta) {
|
public NMEventGeneratorWithPulser(RandomGenerator rnd, Meta meta) {
|
||||||
super(rnd, meta);
|
super(rnd, meta);
|
||||||
@ -26,14 +26,14 @@ public class NMEventGeneratorWithPulser extends NMEventGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized NMEvent get() {
|
public synchronized NumassEvent get() {
|
||||||
//expected next event
|
//expected next event
|
||||||
if (nextEvent == null) {
|
if (nextEvent == null) {
|
||||||
nextEvent = nextEvent(prevEvent);
|
nextEvent = nextEvent(prevEvent);
|
||||||
}
|
}
|
||||||
//if pulser event is first, then leave next event as is and return pulser event
|
//if pulser event is first, then leave next event as is and return pulser event
|
||||||
if (pulserEvent.getTime() < nextEvent.getTime()) {
|
if (pulserEvent.getTime() < nextEvent.getTime()) {
|
||||||
NMEvent res = pulserEvent;
|
NumassEvent res = pulserEvent;
|
||||||
pulserEvent = generatePulserEvent();
|
pulserEvent = generatePulserEvent();
|
||||||
return res;
|
return res;
|
||||||
} else {
|
} else {
|
||||||
@ -44,7 +44,7 @@ public class NMEventGeneratorWithPulser extends NMEventGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private NMEvent generatePulserEvent() {
|
private NumassEvent generatePulserEvent() {
|
||||||
short channel = (short) pulserChanelDistribution.sample();
|
short channel = (short) pulserChanelDistribution.sample();
|
||||||
double time;
|
double time;
|
||||||
if (pulserEvent == null) {
|
if (pulserEvent == null) {
|
||||||
@ -52,6 +52,6 @@ public class NMEventGeneratorWithPulser extends NMEventGenerator {
|
|||||||
} else {
|
} else {
|
||||||
time = pulserEvent.getTime() + pulserDist;
|
time = pulserEvent.getTime() + pulserDist;
|
||||||
}
|
}
|
||||||
return new NMEvent(channel, time);
|
return new NumassEvent(channel, time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,10 @@
|
|||||||
*/
|
*/
|
||||||
package inr.numass.utils;
|
package inr.numass.utils;
|
||||||
|
|
||||||
import inr.numass.data.NMEvent;
|
|
||||||
import inr.numass.data.NumassPoint;
|
import inr.numass.data.NumassPoint;
|
||||||
import inr.numass.data.PointBuilders;
|
import inr.numass.data.PointBuilders;
|
||||||
import inr.numass.data.RawNMPoint;
|
import inr.numass.data.RawNMPoint;
|
||||||
|
import inr.numass.data.events.NumassEvent;
|
||||||
import org.apache.commons.math3.random.RandomGenerator;
|
import org.apache.commons.math3.random.RandomGenerator;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -25,14 +25,14 @@ public class PileUpSimulator {
|
|||||||
private final static double us = 1e-6;//microsecond
|
private final static double us = 1e-6;//microsecond
|
||||||
private final double pointLength;
|
private final double pointLength;
|
||||||
private final RandomGenerator rnd;
|
private final RandomGenerator rnd;
|
||||||
private final List<NMEvent> generated = new ArrayList<>();
|
private final List<NumassEvent> generated = new ArrayList<>();
|
||||||
private final List<NMEvent> pileup = new ArrayList<>();
|
private final List<NumassEvent> pileup = new ArrayList<>();
|
||||||
private final List<NMEvent> registered = new ArrayList<>();
|
private final List<NumassEvent> registered = new ArrayList<>();
|
||||||
private Supplier<NMEvent> generator;
|
private Supplier<NumassEvent> generator;
|
||||||
private double uSet = 0;
|
private double uSet = 0;
|
||||||
private AtomicInteger doublePileup = new AtomicInteger(0);
|
private AtomicInteger doublePileup = new AtomicInteger(0);
|
||||||
|
|
||||||
public PileUpSimulator(double length, RandomGenerator rnd, Supplier<NMEvent> sup) {
|
public PileUpSimulator(double length, RandomGenerator rnd, Supplier<NumassEvent> sup) {
|
||||||
this.rnd = rnd;
|
this.rnd = rnd;
|
||||||
generator = sup;//new NMEventGenerator(countRate, rnd);
|
generator = sup;//new NMEventGenerator(countRate, rnd);
|
||||||
this.pointLength = length;
|
this.pointLength = length;
|
||||||
@ -44,7 +44,7 @@ public class PileUpSimulator {
|
|||||||
this.pointLength = length;
|
this.pointLength = length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PileUpSimulator withGenerator(Supplier<NMEvent> sup){
|
public PileUpSimulator withGenerator(Supplier<NumassEvent> sup){
|
||||||
this.generator = sup;
|
this.generator = sup;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@ public class PileUpSimulator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized PileUpSimulator generate() {
|
public synchronized PileUpSimulator generate() {
|
||||||
NMEvent next;
|
NumassEvent next;
|
||||||
double lastRegisteredTime = 0; // Time of DAQ closing
|
double lastRegisteredTime = 0; // Time of DAQ closing
|
||||||
//flag that shows that previous event was pileup
|
//flag that shows that previous event was pileup
|
||||||
boolean pileupFlag = false;
|
boolean pileupFlag = false;
|
||||||
@ -136,7 +136,7 @@ public class PileUpSimulator {
|
|||||||
} else {
|
} else {
|
||||||
//pileup event
|
//pileup event
|
||||||
short newChannel = pileupChannel(delay, next.getChanel(), next.getChanel());
|
short newChannel = pileupChannel(delay, next.getChanel(), next.getChanel());
|
||||||
NMEvent newEvent = new NMEvent(newChannel, next.getTime());
|
NumassEvent newEvent = new NumassEvent(newChannel, next.getTime());
|
||||||
//replace already registered event by event with new channel
|
//replace already registered event by event with new channel
|
||||||
registered.remove(registered.size() - 1);
|
registered.remove(registered.size() - 1);
|
||||||
registered.add(newEvent);
|
registered.add(newEvent);
|
||||||
|
Loading…
Reference in New Issue
Block a user