A lot of minor fixes. Moving some code to kotlin

This commit is contained in:
Alexander Nozik 2017-12-14 11:19:36 +03:00
parent 4b323fd145
commit e61da4b5fd
4 changed files with 45 additions and 25 deletions

View File

@ -1,5 +1,5 @@
plugins { plugins {
id "org.jetbrains.kotlin.jvm" version "1.2.0" apply false id "org.jetbrains.kotlin.jvm" version "1.2.10" apply false
} }
allprojects{ allprojects{
@ -21,8 +21,8 @@ allprojects{
} }
dependencies{ dependencies{
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:1.2.0" compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:1.2.10"
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.0" compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.10"
} }

View File

@ -59,8 +59,8 @@ class SmartAnalyzer(processor: SignalProcessor? = null) : AbstractAnalyzer(proce
return ValueMap(map) return ValueMap(map)
} }
override fun getEvents(block: NumassBlock, config: Meta): Stream<NumassEvent> { override fun getEvents(block: NumassBlock, meta: Meta): Stream<NumassEvent> {
return getAnalyzer(config).getEvents(block, config) return getAnalyzer(meta).getEvents(block, meta)
} }
override fun getTableFormat(config: Meta): TableFormat { override fun getTableFormat(config: Meta): TableFormat {

View File

@ -194,12 +194,12 @@ class TimeAnalyzer @JvmOverloads constructor(private val processor: SignalProces
* The filtered stream of events * The filtered stream of events
* *
* @param block * @param block
* @param config * @param meta
* @return * @return
*/ */
override fun getEvents(block: NumassBlock, config: Meta): Stream<NumassEvent> { override fun getEvents(block: NumassBlock, meta: Meta): Stream<NumassEvent> {
val t0 = getT0(block, config).toLong() val t0 = getT0(block, meta).toLong()
return getEventsWithDelay(block, config).filter { pair -> pair.second >= t0 }.map { it.first } return getEventsWithDelay(block, meta).filter { pair -> pair.second >= t0 }.map { it.first }
} }
public override fun getTableFormat(config: Meta): TableFormat { public override fun getTableFormat(config: Meta): TableFormat {

View File

@ -19,10 +19,10 @@ package inr.numass.scripts
import hep.dataforge.fx.plots.PlotManager import hep.dataforge.fx.plots.PlotManager
import hep.dataforge.kodex.buildContext import hep.dataforge.kodex.buildContext
import hep.dataforge.kodex.buildMeta import hep.dataforge.kodex.buildMeta
import hep.dataforge.kodex.replaceColumn
import hep.dataforge.meta.Meta import hep.dataforge.meta.Meta
import hep.dataforge.plots.PlotPlugin import hep.dataforge.plots.PlotPlugin
import hep.dataforge.plots.data.DataPlot import hep.dataforge.plots.data.DataPlot
import hep.dataforge.tables.Adapters
import inr.numass.NumassPlugin import inr.numass.NumassPlugin
import inr.numass.data.NumassDataUtils import inr.numass.data.NumassDataUtils
import inr.numass.data.analyzers.NumassAnalyzer import inr.numass.data.analyzers.NumassAnalyzer
@ -65,37 +65,57 @@ fun main(args: Array<String>) {
val meta = buildMeta { val meta = buildMeta {
node("window"){ node("window"){
"lo" to 300 "lo" to 300
"up" to 1800 "up" to 2600
} }
} }
with(NumassAnalyzer) { with(NumassAnalyzer) {
val events = getSpectrum(seconds, analyzer.getEvents(point).asSequence(),meta) val events = getSpectrum(seconds, analyzer.getEvents(point).asSequence(),meta)
.withBinning(binning) .withBinning(binning)
val eventsNorming = events.getColumn(COUNT_RATE_KEY).stream().mapToDouble{it.doubleValue()}.sum()
println("The norming factor for unfiltered count rate is $eventsNorming")
val filtered = getSpectrum( val filtered = getSpectrum(
seconds, seconds,
analyzer.getEventsPairs(point, Meta.empty()).filter { it.second.timeOffset - it.first.timeOffset > t0 }.map { it.second }, analyzer.getEventsPairs(point, Meta.empty()).filter { it.second.timeOffset - it.first.timeOffset > t0 }.map { it.second },
meta meta
).withBinning(binning) ).withBinning(binning)
val filteredNorming = filtered.getColumn(COUNT_RATE_KEY).stream().mapToDouble{it.doubleValue()}.sum()
println("The norming factor for filtered count rate is $filteredNorming")
val defaultFiltered = getSpectrum(
seconds,
analyzer.getEvents(point, buildMeta {"t0" to t0}).asSequence(),
meta
).withBinning(binning)
val defaultFilteredNorming = filtered.getColumn(COUNT_RATE_KEY).stream().mapToDouble{it.doubleValue()}.sum()
println("The norming factor for default filtered count rate is $defaultFilteredNorming")
plots.getPlotFrame("amps").apply { plots.getPlotFrame("amps").apply {
add(DataPlot.plot("events", ADAPTER, events)) add(DataPlot.plot("events", ADAPTER, events.replaceColumn(COUNT_RATE_KEY){getDouble(COUNT_RATE_KEY)/eventsNorming}))
add(DataPlot.plot("filtered", ADAPTER, filtered)) add(DataPlot.plot("filtered", ADAPTER, filtered.replaceColumn(COUNT_RATE_KEY){getDouble(COUNT_RATE_KEY)/filteredNorming}))
add(DataPlot.plot("defaultFiltered", ADAPTER, defaultFiltered.replaceColumn(COUNT_RATE_KEY){getDouble(COUNT_RATE_KEY)/defaultFilteredNorming}))
} }
plots.getPlotFrame("ratio").apply { // plots.getPlotFrame("ratio").apply {
//
add( // add(
DataPlot.plot( // DataPlot.plot(
"ratio", // "ratio",
Adapters.DEFAULT_XY_ADAPTER, // Adapters.DEFAULT_XY_ADAPTER,
events.zip(filtered) { f, s -> // events.zip(filtered) { f, s ->
Adapters.buildXYDataPoint(f.getDouble(CHANNEL_KEY), f.getDouble(COUNT_RATE_KEY) / s.getDouble(COUNT_RATE_KEY)) // Adapters.buildXYDataPoint(f.getDouble(CHANNEL_KEY), f.getDouble(COUNT_RATE_KEY) / s.getDouble(COUNT_RATE_KEY))
} // }
) // )
) // )
} // }
} }