From bbefa9d990a93f3c2c2be996880a4613a06f2bc2 Mon Sep 17 00:00:00 2001 From: darksnake Date: Wed, 22 Jun 2016 16:55:44 +0300 Subject: [PATCH] [no commit message] --- .../generators/EventChainGenerator.java | 16 ++--- ...ntGenerator.java => NMEventGenerator.java} | 61 +++++++++++-------- .../inr/numass/utils/PileUpSimulator.java | 28 +++++++++ 3 files changed, 73 insertions(+), 32 deletions(-) rename numass-main/src/main/java/inr/numass/generators/{EventGenerator.java => NMEventGenerator.java} (68%) create mode 100644 numass-main/src/main/java/inr/numass/utils/PileUpSimulator.java diff --git a/numass-main/src/main/java/inr/numass/generators/EventChainGenerator.java b/numass-main/src/main/java/inr/numass/generators/EventChainGenerator.java index 607c89be..78a5201b 100644 --- a/numass-main/src/main/java/inr/numass/generators/EventChainGenerator.java +++ b/numass-main/src/main/java/inr/numass/generators/EventChainGenerator.java @@ -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 generatedChain = new ArrayList<>(); - private final EventGenerator generator; + private final NMEventGenerator generator; private final double length; private final List pileupChain = new ArrayList<>(); private final List 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 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(); diff --git a/numass-main/src/main/java/inr/numass/generators/EventGenerator.java b/numass-main/src/main/java/inr/numass/generators/NMEventGenerator.java similarity index 68% rename from numass-main/src/main/java/inr/numass/generators/EventGenerator.java rename to numass-main/src/main/java/inr/numass/generators/NMEventGenerator.java index cf66c1c4..e8d453b7 100644 --- a/numass-main/src/main/java/inr/numass/generators/EventGenerator.java +++ b/numass-main/src/main/java/inr/numass/generators/NMEventGenerator.java @@ -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,34 +40,32 @@ 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 shorts = new ArrayList<>(); - for (NMEvent event : point.getEvents()) { - if((event.getChanel()>minChanel)&&(event.getChanel() ((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++) { doubles[i] = shorts.get(i); } - + EmpiricalDistribution d = new EmpiricalDistribution(); d.load(doubles); - + distribution = d; } - - public void loadFromSpectrum(Map spectrum, int minChanel, int maxChanel){ + + public void loadSpectrum(Map 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; @@ -78,15 +77,29 @@ public class EventGenerator { distribution = new EnumeratedRealDistribution(chanels, values); } - public NMEvent nextEvent(NMEvent prev) { - //пока без канала - short chanel = 1600; - - if(distribution!=null){ - chanel = (short) distribution.sample(); + 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; + + if (distribution != null) { + chanel = (short) distribution.sample(); + } else { + chanel = 1600; + } + return new NMEvent(chanel, prev.getTime() + nextExp(1 / cr)); } diff --git a/numass-main/src/main/java/inr/numass/utils/PileUpSimulator.java b/numass-main/src/main/java/inr/numass/utils/PileUpSimulator.java new file mode 100644 index 00000000..5c3a83c2 --- /dev/null +++ b/numass-main/src/main/java/inr/numass/utils/PileUpSimulator.java @@ -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 + */ +public class PileUpSimulator { + + private NMEventGenerator generator; + private final List generated = new ArrayList<>(); + private final List pileup = new ArrayList<>(); + private final List registred = new ArrayList<>(); + + private Function firstEventSurvivalProb; + private Function secondEventSurvivalProb; + +}