[no commit message]

This commit is contained in:
Alexander Nozik 2016-05-02 18:23:03 +03:00
parent ce626fdb25
commit 3a10cc0672
39 changed files with 995 additions and 987 deletions

View File

@ -16,8 +16,8 @@ dependencies {
compile group: 'commons-io', name: 'commons-io', version:'2.+'
compile project(':dataforge-fitting:dataforge-minuit')
compile project(':dataforge-fx')
compile project(':dataforge-grind')
compile project(':dataforge-plots')
compile project(':numass-storage')
}
task runNumass(dependsOn: classes, type : JavaExec){

View File

@ -1,15 +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.
#

View File

@ -20,9 +20,9 @@ import hep.dataforge.data.binary.Binary;
import hep.dataforge.io.BasicIOManager;
import hep.dataforge.meta.Meta;
import hep.dataforge.names.Name;
import inr.numass.data.NumassDataReader;
import inr.numass.storage.NumassDataReader;
import inr.numass.data.NumassPawReader;
import inr.numass.data.RawNMFile;
import inr.numass.storage.RawNMFile;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

View File

@ -0,0 +1,32 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package inr.numass;
import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.storage.commons.StorageDataFactory;
import hep.dataforge.workspace.BasicWorkspace;
import hep.dataforge.workspace.Workspace;
/**
*
* @author Alexander Nozik
*/
public class WorkspaceTest {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String storagepath = "D:\\Work\\Numass\\data\\";
Workspace workspace = BasicWorkspace.builder()
.setContext(new NumassContext())
.loadData("", new StorageDataFactory(), new MetaBuilder("storage").putValue("path", storagepath))
.build();
}
}

View File

@ -18,8 +18,8 @@ package inr.numass.actions;
import hep.dataforge.tables.MapPoint;
import hep.dataforge.tables.SimplePointSource;
import hep.dataforge.values.Value;
import inr.numass.data.NMFile;
import inr.numass.data.NMPoint;
import inr.numass.storage.NMFile;
import inr.numass.storage.NMPoint;
import java.util.HashMap;
import java.util.Map;

View File

@ -22,8 +22,8 @@ import hep.dataforge.description.ValueDef;
import hep.dataforge.exceptions.ContentException;
import hep.dataforge.io.reports.Reportable;
import hep.dataforge.meta.Laminate;
import inr.numass.data.RawNMFile;
import inr.numass.data.RawNMPoint;
import inr.numass.storage.RawNMFile;
import inr.numass.storage.RawNMPoint;
import inr.numass.debunch.DebunchReport;
import inr.numass.debunch.FrameAnalizer;
import java.io.PrintWriter;

View File

@ -22,8 +22,8 @@ import hep.dataforge.exceptions.ContentException;
import hep.dataforge.io.ColumnedDataWriter;
import hep.dataforge.io.reports.Reportable;
import hep.dataforge.meta.Laminate;
import inr.numass.data.NMFile;
import inr.numass.data.NMPoint;
import inr.numass.storage.NMFile;
import inr.numass.storage.NMPoint;
import java.io.OutputStream;
/**

View File

@ -30,9 +30,9 @@ import hep.dataforge.tables.ListTable;
import hep.dataforge.tables.MapPoint;
import hep.dataforge.tables.Table;
import hep.dataforge.tables.TableFormat;
import inr.numass.data.NMFile;
import inr.numass.data.NMPoint;
import inr.numass.data.RawNMPoint;
import inr.numass.storage.NMFile;
import inr.numass.storage.NMPoint;
import inr.numass.storage.RawNMPoint;
import java.io.OutputStream;
import java.time.Instant;
import java.util.ArrayList;

View File

@ -25,8 +25,8 @@ import hep.dataforge.exceptions.ContentException;
import hep.dataforge.io.reports.Reportable;
import hep.dataforge.meta.Laminate;
import static inr.numass.NumassIO.getNumassData;
import inr.numass.data.NMFile;
import inr.numass.data.RawNMFile;
import inr.numass.storage.NMFile;
import inr.numass.storage.RawNMFile;
/**
*

View File

@ -26,8 +26,8 @@ import hep.dataforge.meta.Meta;
import hep.dataforge.plots.fx.FXPlotUtils;
import hep.dataforge.plots.jfreechart.JFreeChartFrame;
import inr.numass.data.ESpectrum;
import inr.numass.data.NMFile;
import inr.numass.data.NMPoint;
import inr.numass.storage.NMFile;
import inr.numass.storage.NMPoint;
import java.awt.Color;
import java.io.OutputStream;
import java.util.ArrayList;

View File

@ -19,8 +19,8 @@ import hep.dataforge.tables.MapPoint;
import hep.dataforge.tables.SimplePointSource;
import hep.dataforge.tables.TableFormat;
import hep.dataforge.values.Value;
import inr.numass.data.NMFile;
import inr.numass.data.NMPoint;
import inr.numass.storage.NMFile;
import inr.numass.storage.NMPoint;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

View File

@ -23,8 +23,8 @@ import hep.dataforge.io.ColumnedDataWriter;
import hep.dataforge.io.reports.Reportable;
import hep.dataforge.meta.Laminate;
import hep.dataforge.meta.Meta;
import inr.numass.data.NMFile;
import inr.numass.data.RawNMPoint;
import inr.numass.storage.NMFile;
import inr.numass.storage.RawNMPoint;
import java.io.OutputStream;
import java.util.LinkedHashMap;
import java.util.List;

View File

@ -15,6 +15,7 @@
*/
package inr.numass.data;
import inr.numass.storage.NMPoint;
import hep.dataforge.io.ColumnedDataWriter;
import hep.dataforge.tables.MapPoint;
import hep.dataforge.tables.SimplePointSource;

View File

@ -15,6 +15,7 @@
*/
package inr.numass.data;
import inr.numass.storage.RawNMFile;
import hep.dataforge.data.binary.Binary;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

View File

@ -13,195 +13,195 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package inr.numass.debunch;
import inr.numass.data.NMEvent;
import inr.numass.data.RawNMPoint;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* Хранит сортированный набор событий с возможностью вырезать куски и склеивать
* концы
*
* @author Darksnake
*/
class DebunchData {
/**
* Удаляет из листа события в определенном диапазоне времени. При этом общее
* время не изменяется, поэтому скорость счета меняется. Возвращает
* количество удаленных событий.
*
* @param from
* @param to
* @return
*/
private static List<NMEvent> removeFrame(List<NMEvent> events, Frame frame) {
List<NMEvent> res = new ArrayList<>();
for (NMEvent event : events) {
if (event.getTime() >= frame.getEnd()) {
res.add(new NMEvent(event.getChanel(), event.getTime() - frame.length()));
} else if (event.getTime() <= frame.getBegin()) {
res.add(event);
}
}
return res;
}
private final List<Frame> bunches = new ArrayList<>();
private final List<NMEvent> events;
private final double length;
public DebunchData(RawNMPoint point) {
events = point.getEvents();
Collections.sort(events, new EventComparator());
length = point.getLength();
}
public Frame countInFrame(double start, double length, int lowerChanel, int upperChanel) {
double end;
if (start + length < this.getLength()) {
end = start + length;
} else {
end = this.getLength();
}
ArrayList<NMEvent> sum = new ArrayList<>();
int i = 0;
while ((i < this.size()) && (events.get(i).getTime() < start)) {
i++;
}
while ((i < this.size()) && (events.get(i).getTime() < end)) {
if ((events.get(i).getChanel() >= lowerChanel) && (events.get(i).getChanel() <= upperChanel)) {
sum.add(getEvents().get(i));
}
i++;
}
return new Frame(start, end, sum);
}
/**
* Same as CountInFrame, but it does not copy all of the event times, only
* total count in frame.
*
* @param start
* @param length
* @return
*/
public Frame countInFrameFast(double start, double length, int lowerChanel, int upperChanel) {
//PENDING самый долгий метод
if (start > this.getLength()) {
throw new IllegalArgumentException();
}
double end;
if (start + length < this.getLength()) {
end = start + length;
} else {
end = this.getLength();
}
int sumCount = 0;
int i = 0;
while ((i < this.size()) && (events.get(i).getTime() < start)) {
i++;
}
while ((i < this.size()) && (events.get(i).getTime() < end)) {
if ((events.get(i).getChanel() >= lowerChanel) && (events.get(i).getChanel() <= upperChanel)) {
sumCount++;
}
i++;
}
return new Frame(start, end, sumCount);
}
public List<Frame> getBunches() {
return bunches;
}
/**
* Возвращает скорректированную скорость счета по всему интервалу
*
* @return
*/
public double getCountRate() {
return this.size() / this.getLength();
}
/**
* Медленный метод, вызывать минимальное количество рах
*
* @return
*/
public List<NMEvent> getDebunchedEvents() {
List<NMEvent> res = getEvents();
for (Frame frame : getBunches()) {
res = removeFrame(res, frame);
}
return res;
}
/**
* Медленный метод, вызывать минимальное количество рах
*
* @return
*/
public double getDebunchedLength() {
double res = length;
for (Frame frame : getBunches()) {
res -= frame.length();
}
if (res > 0) {
return res;
} else {
throw new RuntimeException("Zero length point after debunching");
}
}
public List<NMEvent> getEvents() {
return events;
}
/**
* @return the length
*/
public double getLength() {
return length;
}
public void setAsBunch(Frame bunch) {
//FIXME сделать проверку пересечения кадров
this.bunches.add(bunch);
}
public void setAsBunch(double from, double to) {
assert to > from;
setAsBunch(countInFrame(from, to - from,0, RawNMPoint.MAX_CHANEL));
}
public long size() {
return this.getEvents().size();
}
private static class EventComparator implements Comparator<NMEvent> {
@Override
public int compare(NMEvent o1, NMEvent o2) {
return (int) Math.signum(o1.getTime() - o2.getTime());
}
}
}
package inr.numass.debunch;
import inr.numass.storage.NMEvent;
import inr.numass.storage.RawNMPoint;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* Хранит сортированный набор событий с возможностью вырезать куски и склеивать
* концы
*
* @author Darksnake
*/
class DebunchData {
/**
* Удаляет из листа события в определенном диапазоне времени. При этом общее
* время не изменяется, поэтому скорость счета меняется. Возвращает
* количество удаленных событий.
*
* @param from
* @param to
* @return
*/
private static List<NMEvent> removeFrame(List<NMEvent> events, Frame frame) {
List<NMEvent> res = new ArrayList<>();
for (NMEvent event : events) {
if (event.getTime() >= frame.getEnd()) {
res.add(new NMEvent(event.getChanel(), event.getTime() - frame.length()));
} else if (event.getTime() <= frame.getBegin()) {
res.add(event);
}
}
return res;
}
private final List<Frame> bunches = new ArrayList<>();
private final List<NMEvent> events;
private final double length;
public DebunchData(RawNMPoint point) {
events = point.getEvents();
Collections.sort(events, new EventComparator());
length = point.getLength();
}
public Frame countInFrame(double start, double length, int lowerChanel, int upperChanel) {
double end;
if (start + length < this.getLength()) {
end = start + length;
} else {
end = this.getLength();
}
ArrayList<NMEvent> sum = new ArrayList<>();
int i = 0;
while ((i < this.size()) && (events.get(i).getTime() < start)) {
i++;
}
while ((i < this.size()) && (events.get(i).getTime() < end)) {
if ((events.get(i).getChanel() >= lowerChanel) && (events.get(i).getChanel() <= upperChanel)) {
sum.add(getEvents().get(i));
}
i++;
}
return new Frame(start, end, sum);
}
/**
* Same as CountInFrame, but it does not copy all of the event times, only
* total count in frame.
*
* @param start
* @param length
* @return
*/
public Frame countInFrameFast(double start, double length, int lowerChanel, int upperChanel) {
//PENDING самый долгий метод
if (start > this.getLength()) {
throw new IllegalArgumentException();
}
double end;
if (start + length < this.getLength()) {
end = start + length;
} else {
end = this.getLength();
}
int sumCount = 0;
int i = 0;
while ((i < this.size()) && (events.get(i).getTime() < start)) {
i++;
}
while ((i < this.size()) && (events.get(i).getTime() < end)) {
if ((events.get(i).getChanel() >= lowerChanel) && (events.get(i).getChanel() <= upperChanel)) {
sumCount++;
}
i++;
}
return new Frame(start, end, sumCount);
}
public List<Frame> getBunches() {
return bunches;
}
/**
* Возвращает скорректированную скорость счета по всему интервалу
*
* @return
*/
public double getCountRate() {
return this.size() / this.getLength();
}
/**
* Медленный метод, вызывать минимальное количество рах
*
* @return
*/
public List<NMEvent> getDebunchedEvents() {
List<NMEvent> res = getEvents();
for (Frame frame : getBunches()) {
res = removeFrame(res, frame);
}
return res;
}
/**
* Медленный метод, вызывать минимальное количество рах
*
* @return
*/
public double getDebunchedLength() {
double res = length;
for (Frame frame : getBunches()) {
res -= frame.length();
}
if (res > 0) {
return res;
} else {
throw new RuntimeException("Zero length point after debunching");
}
}
public List<NMEvent> getEvents() {
return events;
}
/**
* @return the length
*/
public double getLength() {
return length;
}
public void setAsBunch(Frame bunch) {
//FIXME сделать проверку пересечения кадров
this.bunches.add(bunch);
}
public void setAsBunch(double from, double to) {
assert to > from;
setAsBunch(countInFrame(from, to - from,0, RawNMPoint.MAX_CHANEL));
}
public long size() {
return this.getEvents().size();
}
private static class EventComparator implements Comparator<NMEvent> {
@Override
public int compare(NMEvent o1, NMEvent o2) {
return (int) Math.signum(o1.getTime() - o2.getTime());
}
}
}

View File

@ -13,66 +13,66 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package inr.numass.debunch;
import inr.numass.data.NMEvent;
/**
*
* @author Darksnake
*/
public class DebunchEvent extends NMEvent {
public static double getEventWeight(NMEvent event) {
if (event instanceof DebunchEvent) {
return ((DebunchEvent) event).getWeight();
} else {
return 1;
}
}
private double shift = 0;
/**
* В общем случае принимает значение от 0 (событие полностью выкинуто) до
* 1(событие полностью принято)
*/
private double weight;
public DebunchEvent(NMEvent event, double weight) {
super(event.getChanel(), event.getTime());
this.weight = weight;
}
protected DebunchEvent(double weight, double shift, short chanel, double time) {
super(chanel, time);
this.weight = weight;
this.shift = shift;
}
@Override
public DebunchEvent clone() {
return new DebunchEvent(weight, shift, chanel, time);
}
@Override
public double getTime() {
return super.getTime() + shift;
}
public double getWeight() {
return this.weight;
}
/**
* @param marker
*/
public void setWeight(int marker){
this.weight = marker;
}
public void shiftTime(double shift) {
this.shift += shift;
}
}
package inr.numass.debunch;
import inr.numass.storage.NMEvent;
/**
*
* @author Darksnake
*/
public class DebunchEvent extends NMEvent {
public static double getEventWeight(NMEvent event) {
if (event instanceof DebunchEvent) {
return ((DebunchEvent) event).getWeight();
} else {
return 1;
}
}
private double shift = 0;
/**
* В общем случае принимает значение от 0 (событие полностью выкинуто) до
* 1(событие полностью принято)
*/
private double weight;
public DebunchEvent(NMEvent event, double weight) {
super(event.getChanel(), event.getTime());
this.weight = weight;
}
protected DebunchEvent(double weight, double shift, short chanel, double time) {
super(chanel, time);
this.weight = weight;
this.shift = shift;
}
@Override
public DebunchEvent clone() {
return new DebunchEvent(weight, shift, chanel, time);
}
@Override
public double getTime() {
return super.getTime() + shift;
}
public double getWeight() {
return this.weight;
}
/**
* @param marker
*/
public void setWeight(int marker){
this.weight = marker;
}
public void shiftTime(double shift) {
this.shift += shift;
}
}

View File

@ -13,23 +13,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package inr.numass.debunch;
import inr.numass.data.NMEvent;
import inr.numass.data.RawNMPoint;
import java.util.List;
/**
*
* @author Darksnake
*/
public interface DebunchReport {
RawNMPoint getInitialPoint();
RawNMPoint getPoint();
List<Frame> getBunches();
List<NMEvent> getBunchEvents();
double eventsFiltred();
double timeFiltred();
}
package inr.numass.debunch;
import inr.numass.storage.NMEvent;
import inr.numass.storage.RawNMPoint;
import java.util.List;
/**
*
* @author Darksnake
*/
public interface DebunchReport {
RawNMPoint getInitialPoint();
RawNMPoint getPoint();
List<Frame> getBunches();
List<NMEvent> 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.storage.NMEvent;
import inr.numass.storage.RawNMPoint;
import java.util.ArrayList;
import java.util.List;

View File

@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package inr.numass.debunch;
import inr.numass.data.RawNMPoint;
/**
*
* @author Darksnake
*/
public interface Debuncher {
DebunchReport debunchPoint(RawNMPoint point);
}
package inr.numass.debunch;
import inr.numass.storage.RawNMPoint;
/**
*
* @author Darksnake
*/
public interface Debuncher {
DebunchReport debunchPoint(RawNMPoint point);
}

View File

@ -13,89 +13,89 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package inr.numass.debunch;
import inr.numass.data.NMEvent;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.math3.distribution.PoissonDistribution;
/**
*
* @author Darksnake
*/
public class Frame {
private final double begin;
private final double end;
private List<NMEvent> events;
private final int eventsCount;
public Frame(double begin, double end, List<NMEvent> events) {
assert end > begin;
this.begin = begin;
this.end = end;
this.events = events;
this.eventsCount = events.size();
}
/**
* Сокращенная версия для экономии памяти
*
* @param begin
* @param end
* @param count
*/
public Frame(double begin, double end, int count) {
assert end > begin;
this.begin = begin;
this.end = end;
this.eventsCount = count;
}
public Frame cloneFast() {
return new Frame(begin, end, eventsCount);
}
public double getBegin() {
return begin;
}
public int getCount() {
if (this.events != null) {
return events.size();
} else {
return eventsCount;
}
}
public double getCountRate(){
return this.getCount() / this.length();
}
public double getCountRateError(){
return Math.sqrt(this.getCount()) / this.length();
}
public double getEnd() {
return end;
}
public List<NMEvent> getEvents() {
if(events!=null)
return events;
else
return new ArrayList<>();
}
public double getProbability(double cr){
PoissonDistribution distr = new PoissonDistribution(cr * this.length());
return distr.probability(getCount());
}
public double length() {
assert this.end > this.begin;
return this.end - this.begin;
}
}
package inr.numass.debunch;
import inr.numass.storage.NMEvent;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.math3.distribution.PoissonDistribution;
/**
*
* @author Darksnake
*/
public class Frame {
private final double begin;
private final double end;
private List<NMEvent> events;
private final int eventsCount;
public Frame(double begin, double end, List<NMEvent> events) {
assert end > begin;
this.begin = begin;
this.end = end;
this.events = events;
this.eventsCount = events.size();
}
/**
* Сокращенная версия для экономии памяти
*
* @param begin
* @param end
* @param count
*/
public Frame(double begin, double end, int count) {
assert end > begin;
this.begin = begin;
this.end = end;
this.eventsCount = count;
}
public Frame cloneFast() {
return new Frame(begin, end, eventsCount);
}
public double getBegin() {
return begin;
}
public int getCount() {
if (this.events != null) {
return events.size();
} else {
return eventsCount;
}
}
public double getCountRate(){
return this.getCount() / this.length();
}
public double getCountRateError(){
return Math.sqrt(this.getCount()) / this.length();
}
public double getEnd() {
return end;
}
public List<NMEvent> getEvents() {
if(events!=null)
return events;
else
return new ArrayList<>();
}
public double getProbability(double cr){
PoissonDistribution distr = new PoissonDistribution(cr * this.length());
return distr.probability(getCount());
}
public double length() {
assert this.end > this.begin;
return this.end - this.begin;
}
}

View File

@ -13,230 +13,230 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package inr.numass.debunch;
import inr.numass.data.RawNMPoint;
import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.analysis.interpolation.LinearInterpolator;
import org.apache.commons.math3.util.FastMath;
/**
*
* @author Darksnake
*/
public class FrameAnalizer implements Debuncher {
private static final double POISSON_THRESHOLD = 1e-80;
static double getGaussianCRThreshold(double cr, double frameLength, double prob) {
double[] xs = {9, 8, 7, 6, 5, 4, 3, 2, 1};
double[] probs = {1.15e-19, 6.22e-16, 1.27e-12, 9.86e-10, 2.86e-7, 3.167e-5, 0.001349, 0.0227, 0.1586};
LinearInterpolator interpolator = new LinearInterpolator();
UnivariateFunction function = interpolator.interpolate(probs, xs);
double sigmas = function.value(prob);
return cr + sigmas * Math.sqrt(cr / frameLength);
}
//double frameShift;
double frameLength;
int lowerChanel = 0;
int numCircles = 1;
double rejectionProb;
int upperChanel = RawNMPoint.MAX_CHANEL;
public FrameAnalizer(double rejectionProb, double frameLength) {
this.rejectionProb = rejectionProb;
this.frameLength = frameLength;
}
public FrameAnalizer(double rejectionProb, double frameLength, int lower, int upper) {
assert upper > lower;
this.rejectionProb = rejectionProb;
this.frameLength = frameLength;
this.lowerChanel = lower;
this.upperChanel = upper;
}
public FrameAnalizer(double rejectionProb, double frameLength, int numCircles) {
this.rejectionProb = rejectionProb;
this.frameLength = frameLength;
this.numCircles = numCircles;
}
/**
* Полный аналог Сережиной программы
*
* @param numCicles
* @param prob
* @param frameShift
* @param frameLength
* @return
*/
private DebunchReport cicledDebunch(RawNMPoint point, int numCicles, double prob, double frameShift, double frameLength) {
DebunchReport res = this.debunch(point, prob, frameShift, frameLength);
for (int i = 0; i < numCicles-1; i++) {
res = this.debunch(res, prob, frameShift, frameLength);
}
return res;
}
private DebunchReport debunch(DebunchReport res, double prob, double frameShift, double frameLength) {
return debunch(res.getPoint(), prob, frameShift, frameLength);
}
private DebunchReport debunch(RawNMPoint point, double prob, double frameShift, double frameLength) {
double cr = point.selectChanels(lowerChanel, upperChanel).getCR();
return debunch(point, cr, prob, frameShift, frameLength);
}
private DebunchReport debunch(RawNMPoint point, double averageCR, double prob, double frameShift, double frameLength) {
DebunchData data = new DebunchData(point);
double timeTotal = data.getLength();
// long countTotal = data.size();
double curPos = 0;
double baseThreshold = getCRThreshold(averageCR, frameLength, prob);
Frame workFrame;
boolean bunchFlag = false;// Флаг символизирует, находимся ли мы в состоянии пачки
while (curPos < (data.getLength() - frameLength)) {
workFrame = data.countInFrameFast(curPos, frameLength,lowerChanel,upperChanel);
if (workFrame.getCountRate() > baseThreshold) {
/*
* Если счет в рамке превышает порог, то выкидываем рамку из результата и сдвигаем
* каретку на один шаг. При этом выставляем флаг.
* Если видим флаг,то вырезаем только последний шаг, чтобы избежать двойного вырезания
*/
if (bunchFlag) {
/*Тут возможен косяк, когда две пачки рядом, но не вплотную. Можно сделать
* так, чтобы запоминалось не состояние флага, а конец последнего вырезанного кадра
*/
workFrame = data.countInFrameFast(curPos + frameLength - frameShift, frameShift,lowerChanel,upperChanel);
}
data.setAsBunch(workFrame);
timeTotal -= workFrame.length();
if (timeTotal <= 0) {
throw new RuntimeException("Total time after cleaning is zero.");
}
bunchFlag = true;
} else {
/*
* Если пачки нет, то просто сдвигаем каретку к следующей рамке и убираем флаг
*/
bunchFlag = false;
}
curPos += frameShift;
}
return new DebunchReportImpl(point, data);
}
@Override
public DebunchReport debunchPoint(RawNMPoint point) {
return cicledDebunch(point, numCircles, rejectionProb, frameLength/4, frameLength);
}
private double getCRThreshold(double cr, double frameLength, double prob) {
if (cr * frameLength > 20) {
return getGaussianCRThreshold(cr, frameLength, prob);
} else {
return getPoissonThreshold(cr * frameLength, prob) / frameLength;
}
}
/**
* Returns set of intervals begining with frameStarts[i]. All FrameStart
* should be inside data region
*
* @param frameStarts
* @param frameLength
* @param fast
* @return
*/
private Frame[] getIntervals(DebunchData data, double[] frameStarts, double frameLength, boolean fast) {
Frame[] res = new Frame[frameStarts.length];
for (int i = 0; i < frameStarts.length; i++) {
if (fast) {
res[i] = data.countInFrameFast(frameStarts[i], frameLength,lowerChanel,upperChanel);
} else {
res[i] = data.countInFrame(frameStarts[i], frameLength,lowerChanel,upperChanel);
}
}
return res;
}
/**
* Returns count rate in consequent frames with the length of frameLength.
* The last frame could be shorter than the overs. This method could be used
* for fast distribution calculation.
*
* @param frameLength
* @return
*/
private double[] getNonIntercectFramesCountRate(DebunchData data, double frameLength) {
double dataLength = data.getLength();
int maxFramesCount = (int) Math.ceil(dataLength / frameLength);
if (maxFramesCount < 2) {
throw new IllegalArgumentException("The frameLength is too large.");
}
double[] res = new double[maxFramesCount];
double frameBegin;
for (int i = 0; i < res.length; i++) {
frameBegin = i * frameLength;
res[i] = data.countInFrameFast(frameBegin, frameLength,lowerChanel,upperChanel).getCountRate();
}
return res;
}
private int getPoissonThreshold(double mean, double prob) {
/*
* Находим точку "обнуления" распределения и значения коммулятивной плотности в этой точке.
*/
double pdf = FastMath.exp(-mean);
double cdf = pdf;
int k = 0;
while (pdf > POISSON_THRESHOLD) {
k++;
pdf *= mean / k;
cdf += pdf;
}
/*
* Начинаем считать комулятивную плотность в обратном порядке
*/
cdf = 1 - cdf;
if (pdf <= 0) {
throw new Error();// Проверяем чтобы там точно не было нуля;
}
while (cdf < prob) {
k--;
pdf *= k / mean;
cdf += pdf;
}
return k;
}
private Frame[] getUniformShiftedIntervals(DebunchData data, double frameShift, double frameLength, boolean fast) {
double dataLength = data.getLength();
int maxFramesCount = (int) Math.ceil(dataLength / frameShift);
double[] frameStarts = new double[maxFramesCount];
for (int i = 0; i < frameStarts.length; i++) {
frameStarts[i] = i * frameShift;
}
return getIntervals(data, frameStarts, frameLength, fast);
}
}
package inr.numass.debunch;
import inr.numass.storage.RawNMPoint;
import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.analysis.interpolation.LinearInterpolator;
import org.apache.commons.math3.util.FastMath;
/**
*
* @author Darksnake
*/
public class FrameAnalizer implements Debuncher {
private static final double POISSON_THRESHOLD = 1e-80;
static double getGaussianCRThreshold(double cr, double frameLength, double prob) {
double[] xs = {9, 8, 7, 6, 5, 4, 3, 2, 1};
double[] probs = {1.15e-19, 6.22e-16, 1.27e-12, 9.86e-10, 2.86e-7, 3.167e-5, 0.001349, 0.0227, 0.1586};
LinearInterpolator interpolator = new LinearInterpolator();
UnivariateFunction function = interpolator.interpolate(probs, xs);
double sigmas = function.value(prob);
return cr + sigmas * Math.sqrt(cr / frameLength);
}
//double frameShift;
double frameLength;
int lowerChanel = 0;
int numCircles = 1;
double rejectionProb;
int upperChanel = RawNMPoint.MAX_CHANEL;
public FrameAnalizer(double rejectionProb, double frameLength) {
this.rejectionProb = rejectionProb;
this.frameLength = frameLength;
}
public FrameAnalizer(double rejectionProb, double frameLength, int lower, int upper) {
assert upper > lower;
this.rejectionProb = rejectionProb;
this.frameLength = frameLength;
this.lowerChanel = lower;
this.upperChanel = upper;
}
public FrameAnalizer(double rejectionProb, double frameLength, int numCircles) {
this.rejectionProb = rejectionProb;
this.frameLength = frameLength;
this.numCircles = numCircles;
}
/**
* Полный аналог Сережиной программы
*
* @param numCicles
* @param prob
* @param frameShift
* @param frameLength
* @return
*/
private DebunchReport cicledDebunch(RawNMPoint point, int numCicles, double prob, double frameShift, double frameLength) {
DebunchReport res = this.debunch(point, prob, frameShift, frameLength);
for (int i = 0; i < numCicles-1; i++) {
res = this.debunch(res, prob, frameShift, frameLength);
}
return res;
}
private DebunchReport debunch(DebunchReport res, double prob, double frameShift, double frameLength) {
return debunch(res.getPoint(), prob, frameShift, frameLength);
}
private DebunchReport debunch(RawNMPoint point, double prob, double frameShift, double frameLength) {
double cr = point.selectChanels(lowerChanel, upperChanel).getCR();
return debunch(point, cr, prob, frameShift, frameLength);
}
private DebunchReport debunch(RawNMPoint point, double averageCR, double prob, double frameShift, double frameLength) {
DebunchData data = new DebunchData(point);
double timeTotal = data.getLength();
// long countTotal = data.size();
double curPos = 0;
double baseThreshold = getCRThreshold(averageCR, frameLength, prob);
Frame workFrame;
boolean bunchFlag = false;// Флаг символизирует, находимся ли мы в состоянии пачки
while (curPos < (data.getLength() - frameLength)) {
workFrame = data.countInFrameFast(curPos, frameLength,lowerChanel,upperChanel);
if (workFrame.getCountRate() > baseThreshold) {
/*
* Если счет в рамке превышает порог, то выкидываем рамку из результата и сдвигаем
* каретку на один шаг. При этом выставляем флаг.
* Если видим флаг,то вырезаем только последний шаг, чтобы избежать двойного вырезания
*/
if (bunchFlag) {
/*Тут возможен косяк, когда две пачки рядом, но не вплотную. Можно сделать
* так, чтобы запоминалось не состояние флага, а конец последнего вырезанного кадра
*/
workFrame = data.countInFrameFast(curPos + frameLength - frameShift, frameShift,lowerChanel,upperChanel);
}
data.setAsBunch(workFrame);
timeTotal -= workFrame.length();
if (timeTotal <= 0) {
throw new RuntimeException("Total time after cleaning is zero.");
}
bunchFlag = true;
} else {
/*
* Если пачки нет, то просто сдвигаем каретку к следующей рамке и убираем флаг
*/
bunchFlag = false;
}
curPos += frameShift;
}
return new DebunchReportImpl(point, data);
}
@Override
public DebunchReport debunchPoint(RawNMPoint point) {
return cicledDebunch(point, numCircles, rejectionProb, frameLength/4, frameLength);
}
private double getCRThreshold(double cr, double frameLength, double prob) {
if (cr * frameLength > 20) {
return getGaussianCRThreshold(cr, frameLength, prob);
} else {
return getPoissonThreshold(cr * frameLength, prob) / frameLength;
}
}
/**
* Returns set of intervals begining with frameStarts[i]. All FrameStart
* should be inside data region
*
* @param frameStarts
* @param frameLength
* @param fast
* @return
*/
private Frame[] getIntervals(DebunchData data, double[] frameStarts, double frameLength, boolean fast) {
Frame[] res = new Frame[frameStarts.length];
for (int i = 0; i < frameStarts.length; i++) {
if (fast) {
res[i] = data.countInFrameFast(frameStarts[i], frameLength,lowerChanel,upperChanel);
} else {
res[i] = data.countInFrame(frameStarts[i], frameLength,lowerChanel,upperChanel);
}
}
return res;
}
/**
* Returns count rate in consequent frames with the length of frameLength.
* The last frame could be shorter than the overs. This method could be used
* for fast distribution calculation.
*
* @param frameLength
* @return
*/
private double[] getNonIntercectFramesCountRate(DebunchData data, double frameLength) {
double dataLength = data.getLength();
int maxFramesCount = (int) Math.ceil(dataLength / frameLength);
if (maxFramesCount < 2) {
throw new IllegalArgumentException("The frameLength is too large.");
}
double[] res = new double[maxFramesCount];
double frameBegin;
for (int i = 0; i < res.length; i++) {
frameBegin = i * frameLength;
res[i] = data.countInFrameFast(frameBegin, frameLength,lowerChanel,upperChanel).getCountRate();
}
return res;
}
private int getPoissonThreshold(double mean, double prob) {
/*
* Находим точку "обнуления" распределения и значения коммулятивной плотности в этой точке.
*/
double pdf = FastMath.exp(-mean);
double cdf = pdf;
int k = 0;
while (pdf > POISSON_THRESHOLD) {
k++;
pdf *= mean / k;
cdf += pdf;
}
/*
* Начинаем считать комулятивную плотность в обратном порядке
*/
cdf = 1 - cdf;
if (pdf <= 0) {
throw new Error();// Проверяем чтобы там точно не было нуля;
}
while (cdf < prob) {
k--;
pdf *= k / mean;
cdf += pdf;
}
return k;
}
private Frame[] getUniformShiftedIntervals(DebunchData data, double frameShift, double frameLength, boolean fast) {
double dataLength = data.getLength();
int maxFramesCount = (int) Math.ceil(dataLength / frameShift);
double[] frameStarts = new double[maxFramesCount];
for (int i = 0; i < frameStarts.length; i++) {
frameStarts[i] = i * frameShift;
}
return getIntervals(data, frameStarts, frameLength, fast);
}
}

View File

@ -13,192 +13,192 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package inr.numass.generators;
import inr.numass.data.NMEvent;
import inr.numass.data.RawNMPoint;
import java.util.ArrayList;
import org.apache.commons.math3.random.MersenneTwister;
import org.apache.commons.math3.random.RandomGenerator;
import org.apache.commons.math3.random.SynchronizedRandomGenerator;
/**
*
* @author Darksnake
*/
public class BunchGenerator {
private double bunchCr; // additional count rate in bunch
private double bunchDist;// average distance between bunches
private double bunchLength; // length of bunches
private double cr; // count rate of normal events
private ExpGenerator expGen;
// private ExponentialDistribution expGen;
public BunchGenerator(double cr, double bunchLength, double bunchDist, double bunchCr) {
this.cr = cr;
this.bunchLength = bunchLength;
this.bunchDist = bunchDist;
this.bunchCr = bunchCr;
expGen = new ExpGenerator(new SynchronizedRandomGenerator(new MersenneTwister()));
}
public BunchGenerator(double cr, double bunchLength, double bunchDist, double bunchCr, RandomGenerator gen) {
this.cr = cr;
this.bunchLength = bunchLength;
this.bunchDist = bunchDist;
this.bunchCr = bunchCr;
expGen = new ExpGenerator(gen);
}
public ArrayList<NMEvent> generate(double dist, double length, double timeShift, boolean isBunch) {
ArrayList<NMEvent> res = new ArrayList<>();
ArrayList<Double> events = generateEvents(dist, length);
for (Double event : events) {
if (event < length) {
res.add(new NMEvent((short)0,event + timeShift));
// if (isBunch) {
// res.add(new DebunchEvent(event + timeShift, 10));
// } else {
// res.add(new DebunchEvent(event + timeShift));
// }
}
}
return res;
}
ArrayList<Double> generateEvents(double dist, double timeTotal) {
ArrayList<Double> res = new ArrayList<>();
double timeCount = 0;
double delta;
while (timeCount < timeTotal) {
delta = expGen.nextExp(dist);
timeCount += delta;
if (timeCount < timeTotal) {
res.add(timeCount);
}
}
return res;
}
/**
* Создает пачку с треугольным распределением
*
* @param dist
* @param timeTotal
* @return
*/
ArrayList<Double> generateEventsTriangle(double dist, double timeTotal) {
ArrayList<Double> res = new ArrayList<>();
double timeCount = 0;
double delta;
while (timeCount < timeTotal) {
delta = expGen.nextExp(dist * timeTotal / (timeTotal - timeCount));
timeCount += delta;
if (timeCount < timeTotal) {
res.add(timeCount);
}
}
return res;
}
public ArrayList<NMEvent> 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<>();
ArrayList<Double> events = generateEventsTriangle(dist, length);
for (Double event : events) {
if (event < length) {
res.add(new NMEvent((short)0,event + timeShift));
// if (isBunch) {
// res.add(new DebunchEvent(event + timeShift, 10));
// } else {
// res.add(new DebunchEvent(event + timeShift));
// }
}
}
return res;
}
/**
*
* @param measurementTime - total measurement time
* @return
*/
public RawNMPoint generateWithBunches(double measurementTime) {
ArrayList<NMEvent> res = generateNormalEvents(measurementTime);
ArrayList<Double> bunchList = generateEvents(bunchDist, measurementTime);
for (Double bunchPos : bunchList) {
res.addAll(generate(1 / bunchCr, bunchLength, bunchPos, true));
}
return new RawNMPoint(0, res, measurementTime);
}
/**
*
* @param measurementTime - total measurement time
* @return
*/
public RawNMPoint generateWithRandomBunches(double measurementTime) {
ArrayList<NMEvent> res = generateNormalEvents(measurementTime);
ArrayList<Double> bunchList = generateEvents(bunchDist, measurementTime);
for (Double bunchPos : bunchList) {
double l = expGen.nextSafeGaussian(bunchLength, bunchLength / 3);
double lambda = expGen.nextSafeGaussian(1 / bunchCr, 1 / bunchCr / 3);
res.addAll(generate(lambda, l, bunchPos, true));
}
return new RawNMPoint(0, res, measurementTime);
}
public RawNMPoint generateWithTriangleBunches(double measurementTime) {
ArrayList<NMEvent> res = generateNormalEvents(measurementTime);
ArrayList<Double> bunchList = generateEvents(bunchDist, measurementTime);
for (Double bunchPos : bunchList) {
res.addAll(generateTriangle(1 / bunchCr, bunchLength, bunchPos, true));
}
return new RawNMPoint(0, res, measurementTime);
}
public void setSeed(int seed) {
this.expGen.setSeed(seed);
}
private static class ExpGenerator {
private final RandomGenerator generator;
public ExpGenerator(RandomGenerator generator) {
this.generator = generator;
}
public ExpGenerator(RandomGenerator generator, int seed) {
this.generator = generator;
this.generator.setSeed(seed);
}
void setSeed(int seed) {
generator.setSeed(seed);
}
double nextUniform() {
return generator.nextDouble();
}
double nextExp(double mean) {
double rand = this.nextUniform();
return -mean * Math.log(1 - rand);
}
double nextSafeGaussian(double mean, double sigma) {
double res = -1;
while (res <= 0) {
res = mean + generator.nextGaussian() * sigma;
}
return res;
}
}
}
package inr.numass.generators;
import inr.numass.storage.NMEvent;
import inr.numass.storage.RawNMPoint;
import java.util.ArrayList;
import org.apache.commons.math3.random.MersenneTwister;
import org.apache.commons.math3.random.RandomGenerator;
import org.apache.commons.math3.random.SynchronizedRandomGenerator;
/**
*
* @author Darksnake
*/
public class BunchGenerator {
private double bunchCr; // additional count rate in bunch
private double bunchDist;// average distance between bunches
private double bunchLength; // length of bunches
private double cr; // count rate of normal events
private ExpGenerator expGen;
// private ExponentialDistribution expGen;
public BunchGenerator(double cr, double bunchLength, double bunchDist, double bunchCr) {
this.cr = cr;
this.bunchLength = bunchLength;
this.bunchDist = bunchDist;
this.bunchCr = bunchCr;
expGen = new ExpGenerator(new SynchronizedRandomGenerator(new MersenneTwister()));
}
public BunchGenerator(double cr, double bunchLength, double bunchDist, double bunchCr, RandomGenerator gen) {
this.cr = cr;
this.bunchLength = bunchLength;
this.bunchDist = bunchDist;
this.bunchCr = bunchCr;
expGen = new ExpGenerator(gen);
}
public ArrayList<NMEvent> generate(double dist, double length, double timeShift, boolean isBunch) {
ArrayList<NMEvent> res = new ArrayList<>();
ArrayList<Double> events = generateEvents(dist, length);
for (Double event : events) {
if (event < length) {
res.add(new NMEvent((short)0,event + timeShift));
// if (isBunch) {
// res.add(new DebunchEvent(event + timeShift, 10));
// } else {
// res.add(new DebunchEvent(event + timeShift));
// }
}
}
return res;
}
ArrayList<Double> generateEvents(double dist, double timeTotal) {
ArrayList<Double> res = new ArrayList<>();
double timeCount = 0;
double delta;
while (timeCount < timeTotal) {
delta = expGen.nextExp(dist);
timeCount += delta;
if (timeCount < timeTotal) {
res.add(timeCount);
}
}
return res;
}
/**
* Создает пачку с треугольным распределением
*
* @param dist
* @param timeTotal
* @return
*/
ArrayList<Double> generateEventsTriangle(double dist, double timeTotal) {
ArrayList<Double> res = new ArrayList<>();
double timeCount = 0;
double delta;
while (timeCount < timeTotal) {
delta = expGen.nextExp(dist * timeTotal / (timeTotal - timeCount));
timeCount += delta;
if (timeCount < timeTotal) {
res.add(timeCount);
}
}
return res;
}
public ArrayList<NMEvent> 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<>();
ArrayList<Double> events = generateEventsTriangle(dist, length);
for (Double event : events) {
if (event < length) {
res.add(new NMEvent((short)0,event + timeShift));
// if (isBunch) {
// res.add(new DebunchEvent(event + timeShift, 10));
// } else {
// res.add(new DebunchEvent(event + timeShift));
// }
}
}
return res;
}
/**
*
* @param measurementTime - total measurement time
* @return
*/
public RawNMPoint generateWithBunches(double measurementTime) {
ArrayList<NMEvent> res = generateNormalEvents(measurementTime);
ArrayList<Double> bunchList = generateEvents(bunchDist, measurementTime);
for (Double bunchPos : bunchList) {
res.addAll(generate(1 / bunchCr, bunchLength, bunchPos, true));
}
return new RawNMPoint(0, res, measurementTime);
}
/**
*
* @param measurementTime - total measurement time
* @return
*/
public RawNMPoint generateWithRandomBunches(double measurementTime) {
ArrayList<NMEvent> res = generateNormalEvents(measurementTime);
ArrayList<Double> bunchList = generateEvents(bunchDist, measurementTime);
for (Double bunchPos : bunchList) {
double l = expGen.nextSafeGaussian(bunchLength, bunchLength / 3);
double lambda = expGen.nextSafeGaussian(1 / bunchCr, 1 / bunchCr / 3);
res.addAll(generate(lambda, l, bunchPos, true));
}
return new RawNMPoint(0, res, measurementTime);
}
public RawNMPoint generateWithTriangleBunches(double measurementTime) {
ArrayList<NMEvent> res = generateNormalEvents(measurementTime);
ArrayList<Double> bunchList = generateEvents(bunchDist, measurementTime);
for (Double bunchPos : bunchList) {
res.addAll(generateTriangle(1 / bunchCr, bunchLength, bunchPos, true));
}
return new RawNMPoint(0, res, measurementTime);
}
public void setSeed(int seed) {
this.expGen.setSeed(seed);
}
private static class ExpGenerator {
private final RandomGenerator generator;
public ExpGenerator(RandomGenerator generator) {
this.generator = generator;
}
public ExpGenerator(RandomGenerator generator, int seed) {
this.generator = generator;
this.generator.setSeed(seed);
}
void setSeed(int seed) {
generator.setSeed(seed);
}
double nextUniform() {
return generator.nextDouble();
}
double nextExp(double mean) {
double rand = this.nextUniform();
return -mean * Math.log(1 - rand);
}
double nextSafeGaussian(double mean, double sigma) {
double res = -1;
while (res <= 0) {
res = mean + generator.nextGaussian() * sigma;
}
return res;
}
}
}

View File

@ -15,8 +15,8 @@
*/
package inr.numass.generators;
import inr.numass.data.NMEvent;
import inr.numass.data.RawNMPoint;
import inr.numass.storage.NMEvent;
import inr.numass.storage.RawNMPoint;
import static java.lang.Math.max;
import java.util.ArrayList;
import java.util.List;

View File

@ -13,102 +13,102 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package inr.numass.generators;
import inr.numass.data.NMEvent;
import inr.numass.data.RawNMPoint;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.math3.distribution.EnumeratedRealDistribution;
import org.apache.commons.math3.distribution.RealDistribution;
import org.apache.commons.math3.random.EmpiricalDistribution;
import org.apache.commons.math3.random.JDKRandomGenerator;
import org.apache.commons.math3.random.RandomGenerator;
/**
*
* @author Darksnake
*/
public class EventGenerator {
double cr;
// UnivariateFunction signalShape;
RealDistribution distribution;
private final RandomGenerator generator;
public EventGenerator(double cr) {
this.cr = cr;
generator = new JDKRandomGenerator();
}
public void loadFromPoint(RawNMPoint point,int minChanel, int maxChanel){
List<Short> shorts = new ArrayList<>();
for (NMEvent event : point.getEvents()) {
if((event.getChanel()>minChanel)&&(event.getChanel()<maxChanel)) {
shorts.add(event.getChanel());
}
}
double[] doubles = new double[shorts.size()];
for (int i = 0; i < shorts.size(); i++) {
doubles[i] = shorts.get(i);
}
EmpiricalDistribution d = new EmpiricalDistribution();
d.load(doubles);
distribution = d;
}
public void loadFromSpectrum(Map<Double,Double> spectrum, int minChanel, int maxChanel){
assert minChanel > 0;
assert maxChanel < RawNMPoint.MAX_CHANEL;
double[] chanels = new double[spectrum.size()];
double[] values = new double[spectrum.size()];
int i = 0;
for (Map.Entry<Double, Double> entry : spectrum.entrySet()) {
chanels[i] = entry.getKey();
values[i] = entry.getValue();
i++;
}
distribution = new EnumeratedRealDistribution(chanels, values);
}
public NMEvent nextEvent(NMEvent prev) {
//пока без канала
short chanel = 1600;
if(distribution!=null){
chanel = (short) distribution.sample();
}
return new NMEvent(chanel, prev.getTime() + nextExp(1 / cr));
}
double nextExp(double mean) {
double rand = this.nextUniform();
return -mean * Math.log(1 - rand);
}
double nextPositiveGaussian(double mean, double sigma) {
double res = -1;
while (res <= 0) {
res = mean + generator.nextGaussian() * sigma;
}
return res;
}
double nextUniform() {
return generator.nextDouble();
}
void setSeed(int seed) {
generator.setSeed(seed);
}
}
package inr.numass.generators;
import inr.numass.storage.NMEvent;
import inr.numass.storage.RawNMPoint;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.math3.distribution.EnumeratedRealDistribution;
import org.apache.commons.math3.distribution.RealDistribution;
import org.apache.commons.math3.random.EmpiricalDistribution;
import org.apache.commons.math3.random.JDKRandomGenerator;
import org.apache.commons.math3.random.RandomGenerator;
/**
*
* @author Darksnake
*/
public class EventGenerator {
double cr;
// UnivariateFunction signalShape;
RealDistribution distribution;
private final RandomGenerator generator;
public EventGenerator(double cr) {
this.cr = cr;
generator = new JDKRandomGenerator();
}
public void loadFromPoint(RawNMPoint point,int minChanel, int maxChanel){
List<Short> shorts = new ArrayList<>();
for (NMEvent event : point.getEvents()) {
if((event.getChanel()>minChanel)&&(event.getChanel()<maxChanel)) {
shorts.add(event.getChanel());
}
}
double[] doubles = new double[shorts.size()];
for (int i = 0; i < shorts.size(); i++) {
doubles[i] = shorts.get(i);
}
EmpiricalDistribution d = new EmpiricalDistribution();
d.load(doubles);
distribution = d;
}
public void loadFromSpectrum(Map<Double,Double> spectrum, int minChanel, int maxChanel){
assert minChanel > 0;
assert maxChanel < RawNMPoint.MAX_CHANEL;
double[] chanels = new double[spectrum.size()];
double[] values = new double[spectrum.size()];
int i = 0;
for (Map.Entry<Double, Double> entry : spectrum.entrySet()) {
chanels[i] = entry.getKey();
values[i] = entry.getValue();
i++;
}
distribution = new EnumeratedRealDistribution(chanels, values);
}
public NMEvent nextEvent(NMEvent prev) {
//пока без канала
short chanel = 1600;
if(distribution!=null){
chanel = (short) distribution.sample();
}
return new NMEvent(chanel, prev.getTime() + nextExp(1 / cr));
}
double nextExp(double mean) {
double rand = this.nextUniform();
return -mean * Math.log(1 - rand);
}
double nextPositiveGaussian(double mean, double sigma) {
double res = -1;
while (res <= 0) {
res = mean + generator.nextGaussian() * sigma;
}
return res;
}
double nextUniform() {
return generator.nextDouble();
}
void setSeed(int seed) {
generator.setSeed(seed);
}
}

View File

@ -1,10 +1,4 @@
configurations{
all*.exclude module: 'commons-math3'
all*.exclude group: 'org.jfree'
}
dependencies {
compile(project(':numass-main')){transitive = false}
compile project(':dataforge-storage')
compile project(':dataforge-grind')
}

View File

@ -18,8 +18,7 @@ task runClient(type: JavaExec) {
}
dependencies {
compile(project(':numass-storage')){transitive = false}
compile project(':dataforge-storage')
compile(project(':numass-storage'))
compile 'commons-cli:commons-cli:1.3.1'
compile 'org.zeroturnaround:zt-zip:1.9'
}

View File

@ -13,37 +13,37 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package inr.numass.data;
/**
*
* @author Darksnake
*/
public class NMEvent implements Cloneable{
protected final short chanel;
protected final double time;
public NMEvent(short chanel, double time) {
this.chanel = chanel;
this.time = time;
}
@Override
public NMEvent clone() {
return new NMEvent(chanel, time);
}
/**
* @return the chanel
*/
public short getChanel() {
return chanel;
}
/**
* @return the time
*/
public double getTime(){
return time;
}
}
package inr.numass.storage;
/**
*
* @author Darksnake
*/
public class NMEvent implements Cloneable{
protected final short chanel;
protected final double time;
public NMEvent(short chanel, double time) {
this.chanel = chanel;
this.time = time;
}
@Override
public NMEvent clone() {
return new NMEvent(chanel, time);
}
/**
* @return the chanel
*/
public short getChanel() {
return chanel;
}
/**
* @return the time
*/
public double getTime(){
return time;
}
}

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package inr.numass.data;
package inr.numass.storage;
import hep.dataforge.description.ValueDef;
import hep.dataforge.meta.Meta;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package inr.numass.data;
package inr.numass.storage;
import hep.dataforge.tables.DataPoint;
import hep.dataforge.tables.MapPoint;

View File

@ -3,8 +3,9 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package inr.numass.data;
package inr.numass.storage;
import inr.numass.storage.NMPoint;
import hep.dataforge.meta.Meta;
import hep.dataforge.names.Named;
import java.time.Instant;

View File

@ -24,10 +24,6 @@ import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.storage.api.ObjectLoader;
import hep.dataforge.storage.api.Storage;
import hep.dataforge.storage.loaders.AbstractLoader;
import inr.numass.data.NMEvent;
import inr.numass.data.NMPoint;
import inr.numass.data.NumassData;
import inr.numass.data.RawNMPoint;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;

View File

@ -13,8 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package inr.numass.data;
package inr.numass.storage;
import inr.numass.storage.NMEvent;
import inr.numass.storage.RawNMFile;
import inr.numass.storage.RawNMPoint;
import hep.dataforge.data.FileDataFactory;
import hep.dataforge.data.binary.Binary;
import hep.dataforge.meta.Meta;

View File

@ -22,8 +22,6 @@ import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.storage.filestorage.FileStorage;
import hep.dataforge.storage.filestorage.VFSUtils;
import inr.numass.data.NMFile;
import inr.numass.data.NumassData;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package inr.numass.data;
package inr.numass.storage;
import hep.dataforge.names.NamedMetaHolder;
import java.io.BufferedOutputStream;
@ -109,7 +109,7 @@ public class RawNMFile extends NamedMetaHolder {
return points;
}
void putEvent(double U, short chanel, double time) {
public void putEvent(double U, short chanel, double time) {
for (RawNMPoint point : this.getData()) {
if (U == point.getUread()) {
point.putEvent(new NMEvent(chanel, time));

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package inr.numass.data;
package inr.numass.storage;
import java.time.Instant;
import java.util.ArrayList;

View File

@ -11,8 +11,6 @@ description = "The viewer for numass data"
dependencies {
compile project(':numass-main')
// compile project(':dataforge-storage')
compile project(':numass-storage')
compile project(':dataforge-fx')
compile 'com.jcraft:jsch:0.1.53'
}

View File

@ -21,7 +21,7 @@ import hep.dataforge.context.ProcessManager;
import hep.dataforge.exceptions.StorageException;
import hep.dataforge.fx.ConsoleFragment;
import hep.dataforge.fx.ProcessManagerFragment;
import inr.numass.data.NumassData;
import inr.numass.storage.NumassData;
import inr.numass.storage.NumassStorage;
import java.io.File;
import java.net.URL;

View File

@ -19,7 +19,7 @@ import hep.dataforge.context.ProcessManager;
import hep.dataforge.exceptions.StorageException;
import hep.dataforge.storage.api.Loader;
import hep.dataforge.storage.api.Storage;
import inr.numass.data.NumassData;
import inr.numass.storage.NumassData;
import inr.numass.storage.NumassStorage;
import java.time.Instant;
import java.util.ArrayList;

View File

@ -37,8 +37,8 @@ import hep.dataforge.tables.ListTable;
import hep.dataforge.tables.MapPoint;
import hep.dataforge.tables.Table;
import hep.dataforge.tables.XYAdapter;
import inr.numass.data.NMPoint;
import inr.numass.data.NumassData;
import inr.numass.storage.NMPoint;
import inr.numass.storage.NumassData;
import java.io.File;
import java.io.IOException;
import java.net.URL;