From edef7762f3f50042b2140d025e40151c51dd6234 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 29 Oct 2018 16:50:56 +0300 Subject: [PATCH] Some fixes --- .../numass/data/analyzers/SimpleAnalyzer.kt | 14 +++++++- .../src/main/kotlin/inr/numass/NumassUtils.kt | 8 ++--- .../inr/numass/scripts/analysis/Run2017_11.kt | 36 +++++++++++++++++++ .../numass/scripts/timeanalysis/Histogram.kt | 2 +- .../kotlin/inr/numass/tasks/NumassTasks.kt | 12 +++---- 5 files changed, 58 insertions(+), 14 deletions(-) create mode 100644 numass-main/src/main/kotlin/inr/numass/scripts/analysis/Run2017_11.kt diff --git a/numass-core/src/main/kotlin/inr/numass/data/analyzers/SimpleAnalyzer.kt b/numass-core/src/main/kotlin/inr/numass/data/analyzers/SimpleAnalyzer.kt index 790eb88f..f0fb662d 100644 --- a/numass-core/src/main/kotlin/inr/numass/data/analyzers/SimpleAnalyzer.kt +++ b/numass-core/src/main/kotlin/inr/numass/data/analyzers/SimpleAnalyzer.kt @@ -16,8 +16,10 @@ package inr.numass.data.analyzers +import hep.dataforge.description.ValueDef import hep.dataforge.meta.Meta import hep.dataforge.values.ValueMap +import hep.dataforge.values.ValueType import hep.dataforge.values.Values import inr.numass.data.api.NumassBlock import inr.numass.data.api.SignalProcessor @@ -26,15 +28,25 @@ import inr.numass.data.api.SignalProcessor * A simple event counter * Created by darksnake on 07.07.2017. */ +@ValueDef(key = "deadTime", type = [ValueType.NUMBER], def = "0.0", info = "Dead time in nanoseconds for correction") class SimpleAnalyzer @JvmOverloads constructor(private val processor: SignalProcessor? = null) : AbstractAnalyzer(processor) { override fun analyze(block: NumassBlock, config: Meta): Values { val loChannel = config.getInt("window.lo", 0) val upChannel = config.getInt("window.up", Integer.MAX_VALUE) + val count = getEvents(block, config).count() val length = block.length.toNanos().toDouble() / 1e9 - val countRate = count.toDouble() / length + + val deadTime = config.getDouble("deadTime", 0.0) + + val countRate = if (deadTime > 0) { + val mu = count.toDouble() / length + mu / (1.0 - deadTime * 1e-9 * mu) + } else { + count.toDouble() / length + } val countRateError = Math.sqrt(count.toDouble()) / length return ValueMap.of(AbstractAnalyzer.NAME_LIST, diff --git a/numass-main/src/main/kotlin/inr/numass/NumassUtils.kt b/numass-main/src/main/kotlin/inr/numass/NumassUtils.kt index 1f55ca48..e9752064 100644 --- a/numass-main/src/main/kotlin/inr/numass/NumassUtils.kt +++ b/numass-main/src/main/kotlin/inr/numass/NumassUtils.kt @@ -209,13 +209,13 @@ fun pointExpression(expression: String, point: Values): Double { fun JFreeChartFrame.addSetMarkers(sets: Collection) { val jfcPlot = chart.xyPlot val paint = Color(0.0f, 0.0f, 1.0f, 0.1f) - sets.stream().forEach { - val start = it.startTime; - val stop = it.meta.optValue("end_time").map { it.time } + sets.stream().forEach { set -> + val start = set.startTime; + val stop = set.meta.optValue("end_time").map { it.time } .orElse(start.plusSeconds(300)) .minusSeconds(60) val marker = IntervalMarker(start.toEpochMilli().toDouble(), stop.toEpochMilli().toDouble(), paint) - marker.label = it.name + marker.label = set.name marker.labelFont = Font("Verdana", Font.BOLD, 20); marker.labelOffset = RectangleInsets(30.0, 30.0, 30.0, 30.0) runLater { jfcPlot.addDomainMarker(marker) } diff --git a/numass-main/src/main/kotlin/inr/numass/scripts/analysis/Run2017_11.kt b/numass-main/src/main/kotlin/inr/numass/scripts/analysis/Run2017_11.kt new file mode 100644 index 00000000..eb52af21 --- /dev/null +++ b/numass-main/src/main/kotlin/inr/numass/scripts/analysis/Run2017_11.kt @@ -0,0 +1,36 @@ +package inr.numass.scripts.analysis + +import hep.dataforge.context.Global +import hep.dataforge.plots.plotData +import hep.dataforge.tables.Adapters +import hep.dataforge.tables.Table +import hep.dataforge.workspace.FileBasedWorkspace +import inr.numass.displayChart +import java.io.File + +fun main(args: Array) { + +// val context = buildContext("NUMASS", NumassPlugin::class.java, JFreeChartPlugin::class.java) { +// output = FXOutputManager() +// rootDir = "D:\\Work\\Numass\\sterile2017_11" +// dataDir = "D:\\Work\\Numass\\data\\2017_11" +// properties { +// "cache.enabled" to false +// } +// } + + + val configPath = File("D:\\Work\\Numass\\sterile2017_11\\workspace.groovy").toPath() + + val workspace = FileBasedWorkspace.build(Global, configPath) + + workspace.context.setValue("cache.enabled", false) + + val result = workspace.runTask("dif", "adiab_19").first().get() as Table + + displayChart("Adiabacity").apply { + plotData("Adiabacity_19", result, Adapters.buildXYAdapter("voltage", "cr")) + } + + println("Complete!") +} \ No newline at end of file diff --git a/numass-main/src/main/kotlin/inr/numass/scripts/timeanalysis/Histogram.kt b/numass-main/src/main/kotlin/inr/numass/scripts/timeanalysis/Histogram.kt index 609fda8e..0f4a4b0e 100644 --- a/numass-main/src/main/kotlin/inr/numass/scripts/timeanalysis/Histogram.kt +++ b/numass-main/src/main/kotlin/inr/numass/scripts/timeanalysis/Histogram.kt @@ -52,7 +52,7 @@ fun main(args: Array) { //def sets = (20..28).collect { "set_$it" } val loaders = sets.map { set -> - storage.provide("loader::$set", NumassSet::class.java).orElse(null) + storage.provide("$set", NumassSet::class.java).orElse(null) }.filter { it != null } val joined = NumassDataUtils.join("sum", loaders) diff --git a/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt b/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt index cf8d957c..cfe0c953 100644 --- a/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt +++ b/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt @@ -170,14 +170,10 @@ val subtractEmptyTask = task("dif") { putNode("data", input.meta) putNode("empty", empty.meta) } - val res = DataUtils.combine(input, empty, Table::class.java, resMeta) { mergeData, emptyData -> - subtractSpectrum(mergeData, emptyData, context.logger) - } - - res.goal.onComplete { r, _ -> - if (r != null) { - context.output.get("numass.merge", input.name + "_subtract").render(NumassUtils.wrap(r, resMeta)) - } + val res = DataUtils.combine(context, input, empty, Table::class.java, resMeta) { mergeData, emptyData -> + val dif = subtractSpectrum(mergeData, emptyData, context.logger) + context.output["numass.merge", input.name + "_subtract"].render(NumassUtils.wrap(dif, resMeta)) + dif } builder.putData(input.name, res)