[no commit message]

This commit is contained in:
darksnake 2016-06-22 16:55:44 +03:00
parent 690254d0be
commit bbefa9d990
3 changed files with 73 additions and 32 deletions

View File

@ -23,40 +23,40 @@ import java.util.List;
import java.util.Map;
/**
*
* Utility class for pile-up simulation
* @author Darksnake
*/
public final class EventChainGenerator {
private final static double us = 1e-6;
private final static double us = 1e-6;//microsecond
private double blockStartTime = 0;
private final List<NMEvent> generatedChain = new ArrayList<>();
private final EventGenerator generator;
private final NMEventGenerator generator;
private final double length;
private final List<NMEvent> pileupChain = new ArrayList<>();
private final List<NMEvent> registredChain = new ArrayList<>();
public EventChainGenerator(double cr, double length) {
generator = new EventGenerator(cr);
generator = new NMEventGenerator(cr);
this.length = length;
run();
}
public EventChainGenerator(double cr, double length, RawNMPoint source, int minChanel, int maxChanel) {
generator = new EventGenerator(cr);
this.generator.loadFromPoint(source, minChanel, maxChanel);
generator = new NMEventGenerator(cr);
this.generator.loadSpectrum(source, minChanel, maxChanel);
this.length = length;
run();
}
public EventChainGenerator(double cr, double length, Map<Double,Double> spectrum, int minChanel, int maxChanel) {
generator = new EventGenerator(cr);
this.generator.loadFromSpectrum(spectrum, minChanel, maxChanel);
generator = new NMEventGenerator(cr);
this.generator.loadSpectrum(spectrum, minChanel, maxChanel);
this.length = length;
run();

View File

@ -16,6 +16,7 @@
package inr.numass.generators;
import inr.numass.storage.NMEvent;
import inr.numass.storage.NMPoint;
import inr.numass.storage.RawNMPoint;
import java.util.ArrayList;
import java.util.List;
@ -26,12 +27,12 @@ import org.apache.commons.math3.random.EmpiricalDistribution;
import org.apache.commons.math3.random.JDKRandomGenerator;
import org.apache.commons.math3.random.RandomGenerator;
/**
* A generator for Numass events with given energy spectrum
*
* @author Darksnake
*/
public class EventGenerator {
public class NMEventGenerator {
double cr;
// UnivariateFunction signalShape;
@ -39,18 +40,16 @@ public class EventGenerator {
private final RandomGenerator generator;
public EventGenerator(double cr) {
public NMEventGenerator(double cr) {
this.cr = cr;
generator = new JDKRandomGenerator();
}
public void loadFromPoint(RawNMPoint point,int minChanel, int maxChanel){
public void loadSpectrum(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());
}
}
point.getEvents().stream()
.filter((event) -> ((event.getChanel() > minChanel) && (event.getChanel() < maxChanel)))
.forEach((event) -> shorts.add(event.getChanel()));
double[] doubles = new double[shorts.size()];
for (int i = 0; i < shorts.size(); i++) {
@ -63,7 +62,7 @@ public class EventGenerator {
distribution = d;
}
public void loadFromSpectrum(Map<Double,Double> spectrum, int minChanel, int maxChanel){
public void loadSpectrum(Map<Double, Double> spectrum, int minChanel, int maxChanel) {
assert minChanel > 0;
assert maxChanel < RawNMPoint.MAX_CHANEL;
@ -78,15 +77,29 @@ public class EventGenerator {
distribution = new EnumeratedRealDistribution(chanels, values);
}
public void loadSpectrum(NMPoint point, int minChanel, int maxChanel) {
assert minChanel > 0;
assert maxChanel < RawNMPoint.MAX_CHANEL;
double[] chanels = new double[RawNMPoint.MAX_CHANEL];
double[] values = new double[RawNMPoint.MAX_CHANEL];
for (int i = 0; i < RawNMPoint.MAX_CHANEL; i++) {
chanels[i] = i;
values[i] = point.getCountInChanel(i);
i++;
}
distribution = new EnumeratedRealDistribution(chanels, values);
}
public NMEvent nextEvent(NMEvent prev) {
//пока без канала
short chanel = 1600;
short chanel;
if (distribution != null) {
chanel = (short) distribution.sample();
} else {
chanel = 1600;
}
return new NMEvent(chanel, prev.getTime() + nextExp(1 / cr));
}

View File

@ -0,0 +1,28 @@
/*
* 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.utils;
import inr.numass.generators.NMEventGenerator;
import inr.numass.storage.NMEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
/**
*
* @author Alexander Nozik <altavir@gmail.com>
*/
public class PileUpSimulator {
private NMEventGenerator generator;
private final List<NMEvent> generated = new ArrayList<>();
private final List<NMEvent> pileup = new ArrayList<>();
private final List<NMEvent> registred = new ArrayList<>();
private Function<Double, Double> firstEventSurvivalProb;
private Function<Double, Double> secondEventSurvivalProb;
}