From d32e6ab55f8567adacf08f6b105913c795f26e58 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 8 Oct 2018 16:56:12 +0300 Subject: [PATCH] Threshold calculation for 2017_11 --- .../inr/numass/scripts/PointSliceSpectrum.kt | 51 ++++++------- .../scripts/threshold/FitAllWithPower.kt | 76 +++++++++++++++++++ .../inr/numass/subthreshold/Threshold.kt | 5 -- 3 files changed, 101 insertions(+), 31 deletions(-) create mode 100644 numass-main/src/main/kotlin/inr/numass/scripts/threshold/FitAllWithPower.kt diff --git a/numass-main/src/main/kotlin/inr/numass/scripts/PointSliceSpectrum.kt b/numass-main/src/main/kotlin/inr/numass/scripts/PointSliceSpectrum.kt index 0b55cc64..ad5477eb 100644 --- a/numass-main/src/main/kotlin/inr/numass/scripts/PointSliceSpectrum.kt +++ b/numass-main/src/main/kotlin/inr/numass/scripts/PointSliceSpectrum.kt @@ -5,69 +5,68 @@ import hep.dataforge.meta.buildMeta import hep.dataforge.nullable import hep.dataforge.plots.PlotGroup import hep.dataforge.plots.data.DataPlot -import hep.dataforge.toList import inr.numass.NumassPlugin import inr.numass.data.analyzers.NumassAnalyzer import inr.numass.data.analyzers.SmartAnalyzer import inr.numass.data.analyzers.withBinning import inr.numass.data.api.NumassSet -import inr.numass.data.api.SimpleBlock import inr.numass.data.storage.NumassDirectory import inr.numass.displayChart -import kotlinx.coroutines.experimental.runBlocking -import java.time.Duration /** * Investigating slices of single point for differences at the beginning and end */ fun main(args: Array) { val context = buildContext("NUMASS", NumassPlugin::class.java) { - rootDir = "D:\\Work\\Numass\\sterile\\2017_11" - dataDir = "D:\\Work\\Numass\\data\\2017_11" + rootDir = "D:\\Work\\Numass\\sterile\\2017_05" + dataDir = "D:\\Work\\Numass\\data\\2017_05_frames" } //val rootDir = File("D:\\Work\\Numass\\data\\2017_05\\Fill_2") - val storage = NumassDirectory.read(context, "Fill_3b") ?: error("Storage not found") + val storage = NumassDirectory.read(context, "Fill_3_events") ?: error("Storage not found") val analyzer = SmartAnalyzer() val meta = buildMeta { "t0" to 15e3 - "window.lo" to 400 - "window.up" to 1600 +// "window.lo" to 400 +// "window.up" to 1600 } - val set = storage.provide("set_17", NumassSet::class.java).nullable ?: error("Set does not exist") + val set = storage.provide("set_58", NumassSet::class.java).nullable ?: error("Set does not exist") val frame = displayChart("slices").apply { plots.setType() plots.configureValue("showLine", true) } - listOf(0,58,103).forEach { index -> + listOf(10, 58, 103).forEach { index -> val group = PlotGroup("point_$index") group.setType() val point = set.find { it.index == index } ?: error("Point not found") - val blockSizes = point.meta.getValue("events").list.map { it.int } - val startTimes = point.meta.getValue("start_time").list.map { it.time } +// val blockSizes = point.meta.getValue("events").list.map { it.int } +// val startTimes = point.meta.getValue("start_time").list.map { it.time } + group.add(DataPlot.plot("spectrum", analyzer.getAmplitudeSpectrum(point, meta).withBinning(32), NumassAnalyzer.AMPLITUDE_ADAPTER)) - runBlocking { - val events = point.events.toList() - var startIndex = 0 - val blocks = blockSizes.zip(startTimes).map { (size, startTime) -> - SimpleBlock.produce(startTime, Duration.ofSeconds(5)) { - events.subList(startIndex, startIndex + size) - }.also { startIndex += size } - } - - blocks.forEachIndexed { index, block -> - group.add(DataPlot.plot("block_$index", analyzer.getAmplitudeSpectrum(block).withBinning(20), NumassAnalyzer.AMPLITUDE_ADAPTER)) - } - } +// runBlocking { +// val events = point.events.toList() +// var startIndex = 0 +// val blocks = blockSizes.zip(startTimes).map { (size, startTime) -> +// SimpleBlock.produce(startTime, Duration.ofSeconds(5)) { +// events.subList(startIndex, startIndex + size) +// }.also { startIndex += size } +// } +// +// blocks.forEachIndexed { index, block -> +// group.add(DataPlot.plot("block_$index", analyzer.getAmplitudeSpectrum(block).withBinning(20), NumassAnalyzer.AMPLITUDE_ADAPTER) { +// "visible" to false +// }) +// } +// } frame.add(group) } } \ No newline at end of file diff --git a/numass-main/src/main/kotlin/inr/numass/scripts/threshold/FitAllWithPower.kt b/numass-main/src/main/kotlin/inr/numass/scripts/threshold/FitAllWithPower.kt new file mode 100644 index 00000000..f5ab85e8 --- /dev/null +++ b/numass-main/src/main/kotlin/inr/numass/scripts/threshold/FitAllWithPower.kt @@ -0,0 +1,76 @@ +/* + * Copyright 2018 Alexander Nozik. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package inr.numass.scripts.threshold + +import hep.dataforge.buildContext +import hep.dataforge.fx.output.FXOutputManager +import hep.dataforge.io.DirectoryOutput +import hep.dataforge.io.plus +import hep.dataforge.meta.buildMeta +import hep.dataforge.nullable +import hep.dataforge.plots.data.DataPlot +import hep.dataforge.plots.jfreechart.JFreeChartPlugin +import hep.dataforge.plots.plotData +import hep.dataforge.storage.files.FileStorage +import hep.dataforge.tables.Adapters +import inr.numass.NumassPlugin +import inr.numass.data.NumassDataUtils +import inr.numass.data.api.NumassSet +import inr.numass.data.storage.NumassDirectory +import inr.numass.displayChart +import inr.numass.subthreshold.Threshold + +fun main(args: Array) { + val context = buildContext("NUMASS", NumassPlugin::class.java, JFreeChartPlugin::class.java) { + rootDir = "D:\\Work\\Numass\\sterile\\2017_11" + dataDir = "D:\\Work\\Numass\\data\\2017_11" + output = FXOutputManager() + DirectoryOutput() + } + + val storage = NumassDirectory.read(context, "Fill_2") as? FileStorage ?: error("Storage not found") + + val meta = buildMeta { + "delta" to -150 + "method" to "pow" + "t0" to 15e3 +// "window.lo" to 400 +// "window.up" to 1600 + "xLow" to 450 + "xHigh" to 700 + "upper" to 3100 + "binning" to 20 + } + + val frame = displayChart("correction").apply { + plots.setType() + } + + val sets = (36..42).map { "set_$it" }.map { setName -> + storage.provide(setName, NumassSet::class.java).nullable ?: error("Set does not exist") + } + val name = "fill_2[36-42]" + + val sum = NumassDataUtils.join(name, sets) + + val correctionTable = Threshold.calculateSubThreshold(sum, meta).filter { + it.getDouble("correction") in (1.0..1.2) + } + + frame.plotData("${name}_cor", correctionTable, Adapters.buildXYAdapter("U", "correction")) + frame.plotData("${name}_a", correctionTable, Adapters.buildXYAdapter("U", "a")) + frame.plotData("${name}_beta", correctionTable, Adapters.buildXYAdapter("U", "beta")) +} \ No newline at end of file diff --git a/numass-main/src/main/kotlin/inr/numass/subthreshold/Threshold.kt b/numass-main/src/main/kotlin/inr/numass/subthreshold/Threshold.kt index 66e8c523..22a1349c 100644 --- a/numass-main/src/main/kotlin/inr/numass/subthreshold/Threshold.kt +++ b/numass-main/src/main/kotlin/inr/numass/subthreshold/Threshold.kt @@ -74,11 +74,6 @@ object Threshold { analyzer.getAmplitudeSpectrum(input, this.meta) } } -// val id = buildMeta { -// +meta.getMeta("data") -// +meta.getMeta("analyze") -// } -// return context.getFeature(CachePlugin::class.java).cacheNode("subThreshold", id, spectra) }