Revision of numass data architecture

This commit is contained in:
darksnake 2017-07-06 17:02:22 +03:00
parent 42e762c421
commit 9395ab5467
22 changed files with 311 additions and 110 deletions

View File

@ -18,6 +18,7 @@ package inr.numass.data;
import hep.dataforge.data.FileDataFactory;
import hep.dataforge.data.binary.Binary;
import hep.dataforge.meta.Meta;
import inr.numass.data.events.NumassEvent;
import java.io.*;
import java.time.LocalDateTime;
@ -97,7 +98,7 @@ public class LegacyDataReader {
return date;
}
private NMEvent readEvent(int b, double timeDiv) throws IOException {
private NumassEvent readEvent(int b, double timeDiv) throws IOException {
short chanel;
long time;
@ -125,7 +126,7 @@ public class LegacyDataReader {
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 {
@ -207,7 +208,7 @@ public class LegacyDataReader {
lab = readByte();
List<NMEvent> events = new ArrayList<>();
List<NumassEvent> events = new ArrayList<>();
while (lab == 0xBF) {
skip(4);//badHV
lab = readByte();

View File

@ -10,6 +10,7 @@ import java.util.Map;
import java.util.stream.Collectors;
/**
* A general representation of single voltage measurement.
* Created by darksnake on 13-Apr-17.
*/
public interface NumassPoint {

View File

@ -19,6 +19,7 @@ import hep.dataforge.description.ValueDef;
import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.names.NamedMetaHolder;
import inr.numass.data.events.NumassEvent;
import java.io.BufferedOutputStream;
import java.io.OutputStream;
@ -61,7 +62,7 @@ public class RawNMFile extends NamedMetaHolder {
long counter = 0;
for (RawNMPoint point : this.getData()) {
double U = point.getUread();
for (NMEvent event : point.getEvents()) {
for (NumassEvent event : point.getEvents()) {
counter++;
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) {
// for (RawNMPoint point : this.getData()) {
// if (U == point.getUread()) {
// point.putEvent(new NMEvent(chanel, time));
// point.putEvent(new NumassEvent(chanel, time));
// return;
// }
// }
// RawNMPoint newpoint = new RawNMPoint();
// newpoint.putEvent(new NMEvent(chanel, time));
// newpoint.putEvent(new NumassEvent(chanel, time));
// this.putPoint(newpoint);
// }

View File

@ -15,6 +15,8 @@
*/
package inr.numass.data;
import inr.numass.data.events.NumassEvent;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
@ -30,27 +32,27 @@ public class RawNMPoint {
public static int MAX_CHANEL = 4095;
private Instant startTime;
private final List<NMEvent> events;
private final List<NumassEvent> events;
private double length;
private double uread;
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.uread = U;
this.events = events;
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.uread = Uread;
this.events = events;
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.uread = uread;
this.length = t;
@ -67,7 +69,7 @@ public class RawNMPoint {
// @Override
// public RawNMPoint clone() {
// ArrayList<NMEvent> newevents = new ArrayList<>();
// ArrayList<NumassEvent> newevents = new ArrayList<>();
// newevents.addAll(this.getEvents());
// return new RawNMPoint(getUset(), getUread(), newevents, getLength());
// }
@ -87,7 +89,7 @@ public class RawNMPoint {
/**
* @return the events
*/
public List<NMEvent> getEvents() {
public List<NumassEvent> getEvents() {
return events;
}
@ -130,24 +132,24 @@ public class RawNMPoint {
}
public RawNMPoint merge(RawNMPoint point) {
List<NMEvent> events = new ArrayList<>(this.events);
for (NMEvent newEvent : point.getEvents()) {
events.add(new NMEvent(newEvent.getChanel(), newEvent.getTime() + this.getLength()));
List<NumassEvent> events = new ArrayList<>(this.events);
for (NumassEvent newEvent : point.getEvents()) {
events.add(new NumassEvent(newEvent.getChanel(), newEvent.getTime() + this.getLength()));
}
double length = this.length + point.length;
double uread = (this.uread + point.uread) / 2;
return new RawNMPoint(this.uset, uread, events, length, this.startTime);
}
// void putEvent(NMEvent event) {
// void putEvent(NumassEvent event) {
// events.add(event);
// }
public RawNMPoint selectChanels(int from, int to) {
assert to > from;
List<NMEvent> res = new ArrayList<>();
for (NMEvent event : this.getEvents()) {
List<NumassEvent> res = new ArrayList<>();
for (NumassEvent event : this.getEvents()) {
if ((event.getChanel() >= from) && (event.getChanel() <= to)) {
res.add(event);
}

View File

@ -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);
}

View File

@ -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();
}

View File

@ -13,26 +13,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package inr.numass.data;
package inr.numass.data.events;
/**
*
* A single numass event with given amplitude ant time.
* @author Darksnake
*/
public class NMEvent{
public class NumassEvent {
protected final short chanel;
protected final double time;
public NMEvent(short chanel, double time) {
public NumassEvent(short chanel, double time) {
this.chanel = chanel;
this.time = time;
}
// @Override
// public NMEvent clone() {
// return new NMEvent(chanel, time);
// }
/**
* @return the chanel
*/

View File

@ -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());
}
}

View File

@ -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();
}

View File

@ -30,7 +30,11 @@ import hep.dataforge.storage.filestorage.FileEnvelope;
import hep.dataforge.storage.filestorage.FileStorage;
import hep.dataforge.storage.loaders.AbstractLoader;
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 java.io.IOException;
@ -164,7 +168,7 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
* @return
*/
private synchronized RawNMPoint readRawPoint(Envelope envelope) {
List<NMEvent> events = new ArrayList<>();
List<NumassEvent> events = new ArrayList<>();
double timeCoef = envelope.meta().getDouble("time_coeff", 50);
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());
long time = Integer.toUnsignedLong(buffer.getInt());
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);
}
buffer.clear(); // do something with the data and clear/compact it.

View File

@ -3,6 +3,7 @@ package inr.numass.data
import groovy.transform.CompileStatic
import hep.dataforge.maths.histogram.Histogram
import hep.dataforge.maths.histogram.UnivariateHistogram
import inr.numass.data.events.NumassEvent
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) {
int totalN = 0
double totalT = 0;
NMEvent lastEvent = point.events[0];
NumassEvent lastEvent = point.events[0];
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;
if (t < 0) {
lastEvent = event
@ -32,21 +33,25 @@ class PointAnalyzer {
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) {
List<Double> ts = new ArrayList<>();
NMEvent lastEvent = point.events[0];
static DoubleStream timeChain(int loChannel = 0, int upChannel = 4000, RawNMPoint... points) {
DoubleStream stream = DoubleStream.empty();
for(RawNMPoint point: points){
List<Double> ts = new ArrayList<>();
NumassEvent 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 < 0) {
lastEvent = event
} else if (t >= 0 && event.chanel <= upChannel && event.chanel >= loChannel) {
ts << t
lastEvent = event
for (int i = 1; i < point.events.size(); i++) {
NumassEvent event = point.events[i];
double t = event.time - lastEvent.time;
if (t < 0) {
lastEvent = event
} else if (t >= 0 && event.chanel <= upChannel && event.chanel >= loChannel) {
ts << t
lastEvent = event
}
}
stream = DoubleStream.concat(stream,ts.stream().mapToDouble{it});
}
return ts.stream().mapToDouble { it }
return stream
}
/**
@ -59,12 +64,16 @@ class PointAnalyzer {
* @return
*/
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) {
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 {

View File

@ -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()
}

View File

@ -1,4 +1,4 @@
package inr.numass.scripts
package inr.numass.scripts.times
import hep.dataforge.context.Context
import hep.dataforge.context.Global
@ -25,15 +25,15 @@ GrindShell shell = new GrindShell(ctx)
shell.eval {
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);
def set = "set_6"
def hv = 15000;
def set = "set_1"
def hv = 18400;
def loChannel = 3000;
def upChannel = 3600;
def loChannel = 400;
def upChannel = 2000;
def point = storage.provide("loader::$set/rawPoint::$hv", RawNMPoint.class).get();

View File

@ -15,8 +15,8 @@
*/
package inr.numass.debunch;
import inr.numass.data.NMEvent;
import inr.numass.data.RawNMPoint;
import inr.numass.data.events.NumassEvent;
import java.util.ArrayList;
import java.util.Collections;
@ -40,11 +40,11 @@ class DebunchData {
* @param to
* @return
*/
private static List<NMEvent> removeFrame(List<NMEvent> events, Frame frame) {
List<NMEvent> res = new ArrayList<>();
for (NMEvent event : events) {
private static List<NumassEvent> removeFrame(List<NumassEvent> events, Frame frame) {
List<NumassEvent> res = new ArrayList<>();
for (NumassEvent event : events) {
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()) {
res.add(event);
}
@ -53,7 +53,7 @@ class DebunchData {
}
private final List<Frame> bunches = new ArrayList<>();
private final List<NMEvent> events;
private final List<NumassEvent> events;
private final double length;
public DebunchData(RawNMPoint point) {
@ -71,7 +71,7 @@ class DebunchData {
end = this.getLength();
}
ArrayList<NMEvent> sum = new ArrayList<>();
ArrayList<NumassEvent> sum = new ArrayList<>();
int i = 0;
while ((i < this.size()) && (events.get(i).getTime() < start)) {
@ -146,8 +146,8 @@ class DebunchData {
*
* @return
*/
public List<NMEvent> getDebunchedEvents() {
List<NMEvent> res = getEvents();
public List<NumassEvent> getDebunchedEvents() {
List<NumassEvent> res = getEvents();
for (Frame frame : getBunches()) {
res = removeFrame(res, frame);
}
@ -171,7 +171,7 @@ class DebunchData {
}
}
public List<NMEvent> getEvents() {
public List<NumassEvent> getEvents() {
return events;
}
@ -196,10 +196,10 @@ class DebunchData {
return this.getEvents().size();
}
private static class EventComparator implements Comparator<NMEvent> {
private static class EventComparator implements Comparator<NumassEvent> {
@Override
public int compare(NMEvent o1, NMEvent o2) {
public int compare(NumassEvent o1, NumassEvent o2) {
return (int) Math.signum(o1.getTime() - o2.getTime());
}

View File

@ -15,15 +15,15 @@
*/
package inr.numass.debunch;
import inr.numass.data.NMEvent;
import inr.numass.data.events.NumassEvent;
/**
*
* @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) {
return ((DebunchEvent) event).getWeight();
} else {
@ -39,7 +39,7 @@ public class DebunchEvent extends NMEvent {
*/
private double weight;
public DebunchEvent(NMEvent event, double weight) {
public DebunchEvent(NumassEvent event, double weight) {
super(event.getChanel(), event.getTime());
this.weight = weight;
}

View File

@ -15,8 +15,8 @@
*/
package inr.numass.debunch;
import inr.numass.data.NMEvent;
import inr.numass.data.RawNMPoint;
import inr.numass.data.events.NumassEvent;
import java.util.List;
@ -29,7 +29,7 @@ public interface DebunchReport {
RawNMPoint getPoint();
List<Frame> getBunches();
List<NMEvent> getBunchEvents();
List<NumassEvent> getBunchEvents();
double eventsFiltred();
double timeFiltred();

View File

@ -15,8 +15,8 @@
*/
package inr.numass.debunch;
import inr.numass.data.NMEvent;
import inr.numass.data.RawNMPoint;
import inr.numass.data.events.NumassEvent;
import java.util.ArrayList;
import java.util.List;
@ -52,8 +52,8 @@ public class DebunchReportImpl implements DebunchReport {
}
@Override
public List<NMEvent> getBunchEvents() {
List<NMEvent> res = new ArrayList<>();
public List<NumassEvent> getBunchEvents() {
List<NumassEvent> res = new ArrayList<>();
for (Frame interval : getBunches()) {
res.addAll(interval.getEvents());
}

View File

@ -15,7 +15,7 @@
*/
package inr.numass.debunch;
import inr.numass.data.NMEvent;
import inr.numass.data.events.NumassEvent;
import org.apache.commons.math3.distribution.PoissonDistribution;
import java.util.ArrayList;
@ -29,10 +29,10 @@ public class Frame {
private final double begin;
private final double end;
private List<NMEvent> events;
private List<NumassEvent> events;
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;
this.begin = begin;
this.end = end;
@ -82,7 +82,7 @@ public class Frame {
return end;
}
public List<NMEvent> getEvents() {
public List<NumassEvent> getEvents() {
if(events!=null)
return events;
else

View File

@ -15,8 +15,8 @@
*/
package inr.numass.utils;
import inr.numass.data.NMEvent;
import inr.numass.data.RawNMPoint;
import inr.numass.data.events.NumassEvent;
import org.apache.commons.math3.random.MersenneTwister;
import org.apache.commons.math3.random.RandomGenerator;
import org.apache.commons.math3.random.SynchronizedRandomGenerator;
@ -52,12 +52,12 @@ public class BunchGenerator {
expGen = new ExpGenerator(gen);
}
public ArrayList<NMEvent> generate(double dist, double length, double timeShift, boolean isBunch) {
ArrayList<NMEvent> res = new ArrayList<>();
public ArrayList<NumassEvent> generate(double dist, double length, double timeShift, boolean isBunch) {
ArrayList<NumassEvent> res = new ArrayList<>();
ArrayList<Double> events = generateEvents(dist, length);
for (Double event : events) {
if (event < length) {
res.add(new NMEvent((short)0,event + timeShift));
res.add(new NumassEvent((short)0,event + timeShift));
// if (isBunch) {
// res.add(new DebunchEvent(event + timeShift, 10));
// } else {
@ -104,16 +104,16 @@ public class BunchGenerator {
return res;
}
public ArrayList<NMEvent> generateNormalEvents(double measurementTime) {
public ArrayList<NumassEvent> generateNormalEvents(double measurementTime) {
return generate(1 / cr, measurementTime, 0, false);
}
public ArrayList<NMEvent> generateTriangle(double dist, double length, double timeShift, boolean isBunch) {
ArrayList<NMEvent> res = new ArrayList<>();
public ArrayList<NumassEvent> generateTriangle(double dist, double length, double timeShift, boolean isBunch) {
ArrayList<NumassEvent> res = new ArrayList<>();
ArrayList<Double> events = generateEventsTriangle(dist, length);
for (Double event : events) {
if (event < length) {
res.add(new NMEvent((short)0,event + timeShift));
res.add(new NumassEvent((short)0,event + timeShift));
// if (isBunch) {
// res.add(new DebunchEvent(event + timeShift, 10));
// } else {
@ -131,7 +131,7 @@ public class BunchGenerator {
* @return
*/
public RawNMPoint generateWithBunches(double measurementTime) {
ArrayList<NMEvent> res = generateNormalEvents(measurementTime);
ArrayList<NumassEvent> res = generateNormalEvents(measurementTime);
ArrayList<Double> bunchList = generateEvents(bunchDist, measurementTime);
for (Double bunchPos : bunchList) {
res.addAll(generate(1 / bunchCr, bunchLength, bunchPos, true));
@ -145,7 +145,7 @@ public class BunchGenerator {
* @return
*/
public RawNMPoint generateWithRandomBunches(double measurementTime) {
ArrayList<NMEvent> res = generateNormalEvents(measurementTime);
ArrayList<NumassEvent> res = generateNormalEvents(measurementTime);
ArrayList<Double> bunchList = generateEvents(bunchDist, measurementTime);
for (Double bunchPos : bunchList) {
double l = expGen.nextSafeGaussian(bunchLength, bunchLength / 3);
@ -156,7 +156,7 @@ public class BunchGenerator {
}
public RawNMPoint generateWithTriangleBunches(double measurementTime) {
ArrayList<NMEvent> res = generateNormalEvents(measurementTime);
ArrayList<NumassEvent> res = generateNormalEvents(measurementTime);
ArrayList<Double> bunchList = generateEvents(bunchDist, measurementTime);
for (Double bunchPos : bunchList) {
res.addAll(generateTriangle(1 / bunchCr, bunchLength, bunchPos, true));

View File

@ -16,9 +16,9 @@
package inr.numass.utils;
import hep.dataforge.meta.Meta;
import inr.numass.data.NMEvent;
import inr.numass.data.NumassPoint;
import inr.numass.data.RawNMPoint;
import inr.numass.data.events.NumassEvent;
import org.apache.commons.math3.distribution.EnumeratedRealDistribution;
import org.apache.commons.math3.distribution.RealDistribution;
import org.apache.commons.math3.random.EmpiricalDistribution;
@ -34,12 +34,12 @@ import java.util.function.Supplier;
*
* @author Darksnake
*/
public class NMEventGenerator implements Supplier<NMEvent> {
public class NMEventGenerator implements Supplier<NumassEvent> {
protected final RandomGenerator rnd;
protected double cr;
protected RealDistribution distribution;
protected NMEvent prevEvent;
protected NumassEvent prevEvent;
public NMEventGenerator(RandomGenerator rnd, double 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;
if (distribution != null) {
@ -129,12 +129,12 @@ public class NMEventGenerator implements Supplier<NMEvent> {
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
public synchronized NMEvent get() {
public synchronized NumassEvent get() {
return prevEvent = nextEvent(prevEvent);
}

View File

@ -1,7 +1,7 @@
package inr.numass.utils;
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.RealDistribution;
import org.apache.commons.math3.random.RandomGenerator;
@ -12,8 +12,8 @@ import org.apache.commons.math3.random.RandomGenerator;
public class NMEventGeneratorWithPulser extends NMEventGenerator {
private RealDistribution pulserChanelDistribution;
private double pulserDist;
private NMEvent pulserEvent;
private NMEvent nextEvent;
private NumassEvent pulserEvent;
private NumassEvent nextEvent;
public NMEventGeneratorWithPulser(RandomGenerator rnd, Meta meta) {
super(rnd, meta);
@ -26,14 +26,14 @@ public class NMEventGeneratorWithPulser extends NMEventGenerator {
}
@Override
public synchronized NMEvent get() {
public synchronized NumassEvent get() {
//expected next event
if (nextEvent == null) {
nextEvent = nextEvent(prevEvent);
}
//if pulser event is first, then leave next event as is and return pulser event
if (pulserEvent.getTime() < nextEvent.getTime()) {
NMEvent res = pulserEvent;
NumassEvent res = pulserEvent;
pulserEvent = generatePulserEvent();
return res;
} else {
@ -44,7 +44,7 @@ public class NMEventGeneratorWithPulser extends NMEventGenerator {
}
}
private NMEvent generatePulserEvent() {
private NumassEvent generatePulserEvent() {
short channel = (short) pulserChanelDistribution.sample();
double time;
if (pulserEvent == null) {
@ -52,6 +52,6 @@ public class NMEventGeneratorWithPulser extends NMEventGenerator {
} else {
time = pulserEvent.getTime() + pulserDist;
}
return new NMEvent(channel, time);
return new NumassEvent(channel, time);
}
}

View File

@ -5,10 +5,10 @@
*/
package inr.numass.utils;
import inr.numass.data.NMEvent;
import inr.numass.data.NumassPoint;
import inr.numass.data.PointBuilders;
import inr.numass.data.RawNMPoint;
import inr.numass.data.events.NumassEvent;
import org.apache.commons.math3.random.RandomGenerator;
import java.util.ArrayList;
@ -25,14 +25,14 @@ public class PileUpSimulator {
private final static double us = 1e-6;//microsecond
private final double pointLength;
private final RandomGenerator rnd;
private final List<NMEvent> generated = new ArrayList<>();
private final List<NMEvent> pileup = new ArrayList<>();
private final List<NMEvent> registered = new ArrayList<>();
private Supplier<NMEvent> generator;
private final List<NumassEvent> generated = new ArrayList<>();
private final List<NumassEvent> pileup = new ArrayList<>();
private final List<NumassEvent> registered = new ArrayList<>();
private Supplier<NumassEvent> generator;
private double uSet = 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;
generator = sup;//new NMEventGenerator(countRate, rnd);
this.pointLength = length;
@ -44,7 +44,7 @@ public class PileUpSimulator {
this.pointLength = length;
}
public PileUpSimulator withGenerator(Supplier<NMEvent> sup){
public PileUpSimulator withGenerator(Supplier<NumassEvent> sup){
this.generator = sup;
return this;
}
@ -111,7 +111,7 @@ public class PileUpSimulator {
}
public synchronized PileUpSimulator generate() {
NMEvent next;
NumassEvent next;
double lastRegisteredTime = 0; // Time of DAQ closing
//flag that shows that previous event was pileup
boolean pileupFlag = false;
@ -136,7 +136,7 @@ public class PileUpSimulator {
} else {
//pileup event
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
registered.remove(registered.size() - 1);
registered.add(newEvent);