Numass script to generate pictures for simulated time distribution

This commit is contained in:
Alexander Nozik 2017-11-10 16:15:46 +03:00
parent b15ffe6bda
commit 7dc3d601f7
2 changed files with 23 additions and 11 deletions

View File

@ -3,8 +3,8 @@ package inr.numass.scripts.times
import hep.dataforge.context.Context
import hep.dataforge.context.Global
import hep.dataforge.fx.plots.PlotManager
import hep.dataforge.grind.Grind
import hep.dataforge.grind.GrindShell
import hep.dataforge.meta.Meta
import inr.numass.NumassPlugin
import inr.numass.actions.TimeAnalyzerAction
import inr.numass.data.SimpleChainGenerator
@ -24,20 +24,21 @@ ctx.pluginManager().load(NumassPlugin.class)
new GrindShell(ctx).eval {
double cr = 15e3;
double cr = 30e3;
long length = 30e9;
def num = 5;
def dt = 6.5
def blocks = (1..num).collect {
def generator = new SimpleChainGenerator(1e4 + 1000*num, new JDKRandomGenerator(), { 1000 })
generator.generateBlock(Instant.now().plusNanos(it * length), length)
def generator = new SimpleChainGenerator(cr, new JDKRandomGenerator(), { 1000 })
generator.generateBlock(Instant.now().plusNanos(it * length), length) { prev, next -> next.timeOffset - prev.timeOffset > dt * 1000 }
}
def point = new SimpleNumassPoint(10000, blocks)
def meta = Grind.buildMeta(plotHist: false)
def meta = Meta.empty()//Grind.buildMeta(plotHist: false)
new TimeAnalyzerAction().simpleRun(point, meta);
}

View File

@ -13,24 +13,35 @@ interface ChainGenerator {
fun next(event: NumassEvent?): NumassEvent
fun generateBlock(start: Instant, length: Long): NumassBlock {
fun generateBlock(start: Instant, length: Long, filter: (NumassEvent, NumassEvent) -> Boolean = { _, _ -> true }): NumassBlock {
val events = ArrayList<NumassEvent>()
var event = next(null)
while (event.timeOffset < length) {
events.add(event)
event = next(event)
while (event.timeOffset < length) {
val nextEvent = next(event)
if (filter(event, nextEvent)) {
event = nextEvent
if (event.timeOffset < length) {
events.add(event)
}
}
}
return SimpleBlock(start, Duration.ofNanos(length), events)
}
}
class SimpleChainGenerator(val cr: Double, private var rnd: RandomGenerator = JDKRandomGenerator(), private val amp: () -> Short = { 1 }) : ChainGenerator {
class SimpleChainGenerator(
val cr: Double,
private val rnd: RandomGenerator = JDKRandomGenerator(),
private val amp: (Long) -> Short = { 1 }
) : ChainGenerator {
override fun next(event: NumassEvent?): NumassEvent {
return if (event == null) {
NumassEvent(amp(), Instant.EPOCH, 0)
NumassEvent(amp(0), Instant.EPOCH, 0)
} else {
NumassEvent(amp(), event.blockTime, event.timeOffset + generateDeltaTime())
val deltaT = generateDeltaTime()
NumassEvent(amp(deltaT), event.blockTime, event.timeOffset + deltaT)
}
}