A lot of minor fixes. Moving some code to kotlin
This commit is contained in:
parent
d88110ed49
commit
258711c08c
@ -10,7 +10,6 @@ import hep.dataforge.storage.commons.StorageManager;
|
||||
import hep.dataforge.storage.filestorage.FileStorage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
@ -29,9 +28,15 @@ public class NumassStorageFactory implements StorageType {
|
||||
* @return
|
||||
*/
|
||||
@NotNull
|
||||
public static FileStorage buildLocal(Context context, File file, boolean readOnly, boolean monitor) {
|
||||
public static FileStorage buildLocal(Context context, Path file, boolean readOnly, boolean monitor) {
|
||||
StorageManager manager = context.loadFeature("hep.dataforge:storage", StorageManager.class);
|
||||
return (FileStorage) manager.buildStorage(buildStorageMeta(file.toURI(),readOnly,monitor));
|
||||
return (FileStorage) manager.buildStorage(buildStorageMeta(file.toUri(),readOnly,monitor));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static FileStorage buildLocal(Context context, String path, boolean readOnly, boolean monitor) {
|
||||
Path file = context.getIo().getDataFile(path);
|
||||
return buildLocal(context, file, readOnly, monitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -116,7 +116,7 @@ interface NumassAnalyzer {
|
||||
|
||||
val DEFAULT_ANALYZER: NumassAnalyzer = SmartAnalyzer()
|
||||
|
||||
val ADAPTER: ValuesAdapter = Adapters.buildXYAdapter(CHANNEL_KEY, COUNT_RATE_KEY)
|
||||
val AMPLITUDE_ADAPTER: ValuesAdapter = Adapters.buildXYAdapter(CHANNEL_KEY, COUNT_RATE_KEY)
|
||||
|
||||
// val MAX_CHANNEL = 10000
|
||||
|
||||
@ -131,7 +131,7 @@ interface NumassAnalyzer {
|
||||
* @param sp2
|
||||
* @return
|
||||
*/
|
||||
fun subtractSpectrum(sp1: Table, sp2: Table): Table {
|
||||
fun subtractAmplitudeSpectrum(sp1: Table, sp2: Table): Table {
|
||||
val format = TableFormatBuilder()
|
||||
.addNumber(CHANNEL_KEY, X_VALUE_KEY)
|
||||
.addNumber(COUNT_RATE_KEY, Y_VALUE_KEY)
|
||||
@ -144,7 +144,8 @@ interface NumassAnalyzer {
|
||||
val channel = row1.getDouble(CHANNEL_KEY)
|
||||
val row2 = sp2.rows.asSequence().find { it.getDouble(CHANNEL_KEY) == channel } //t2[channel]
|
||||
if (row2 == null) {
|
||||
builder.row(row1)
|
||||
throw RuntimeException("Reference for channel $channel not found");
|
||||
|
||||
} else {
|
||||
val value = Math.max(row1.getDouble(COUNT_RATE_KEY) - row2.getDouble(COUNT_RATE_KEY), 0.0)
|
||||
val error1 = row1.getDouble(COUNT_RATE_ERROR_KEY)
|
||||
|
@ -40,6 +40,7 @@ import inr.numass.utils.ExpressionUtils
|
||||
import org.apache.commons.math3.analysis.UnivariateFunction
|
||||
import org.jfree.chart.plot.IntervalMarker
|
||||
import org.jfree.chart.ui.RectangleInsets
|
||||
import org.slf4j.Logger
|
||||
import tornadofx.*
|
||||
import java.awt.Color
|
||||
import java.awt.Font
|
||||
@ -220,24 +221,24 @@ fun addSetMarkers(frame: JFreeChartFrame, sets: Collection<NumassSet>) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract one energy spectrum from the other one
|
||||
* Subtract one U spectrum from the other one
|
||||
*/
|
||||
fun subtractAmplitudeSpectrum(context: Context, merge: Table, empty: Table): Table {
|
||||
fun subtractSpectrum(merge: Table, empty: Table, logger: Logger? = null): Table {
|
||||
val builder = ListTable.Builder(merge.format)
|
||||
merge.rows.forEach { point ->
|
||||
val pointBuilder = ValueMap.Builder(point)
|
||||
val referencePoint = empty.rows
|
||||
.filter { p -> Math.abs(p.getDouble(NumassPoint.HV_KEY)!! - point.getDouble(NumassPoint.HV_KEY)!!) < 0.1 }.findFirst()
|
||||
.filter { p -> Math.abs(p.getDouble(NumassPoint.HV_KEY) - point.getDouble(NumassPoint.HV_KEY)) < 0.1 }.findFirst()
|
||||
if (referencePoint.isPresent) {
|
||||
pointBuilder.putValue(
|
||||
NumassAnalyzer.COUNT_RATE_KEY,
|
||||
Math.max(0.0, point.getDouble(NumassAnalyzer.COUNT_RATE_KEY)!! - referencePoint.get().getDouble(NumassAnalyzer.COUNT_RATE_KEY)!!)
|
||||
Math.max(0.0, point.getDouble(NumassAnalyzer.COUNT_RATE_KEY) - referencePoint.get().getDouble(NumassAnalyzer.COUNT_RATE_KEY))
|
||||
)
|
||||
pointBuilder.putValue(
|
||||
NumassAnalyzer.COUNT_RATE_ERROR_KEY,
|
||||
Math.sqrt(Math.pow(point.getDouble(NumassAnalyzer.COUNT_RATE_ERROR_KEY)!!, 2.0) + Math.pow(referencePoint.get().getDouble(NumassAnalyzer.COUNT_RATE_ERROR_KEY)!!, 2.0)))
|
||||
Math.sqrt(Math.pow(point.getDouble(NumassAnalyzer.COUNT_RATE_ERROR_KEY), 2.0) + Math.pow(referencePoint.get().getDouble(NumassAnalyzer.COUNT_RATE_ERROR_KEY), 2.0)))
|
||||
} else {
|
||||
context.logger.warn("No reference point found for voltage = {}", point.getDouble(NumassPoint.HV_KEY))
|
||||
logger?.warn("No reference point found for voltage = {}", point.getDouble(NumassPoint.HV_KEY))
|
||||
}
|
||||
builder.row(pointBuilder.build())
|
||||
}
|
||||
|
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright 2017 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
|
||||
|
||||
import hep.dataforge.fx.plots.PlotManager
|
||||
import hep.dataforge.kodex.buildContext
|
||||
import hep.dataforge.kodex.buildMeta
|
||||
import hep.dataforge.kodex.replaceColumn
|
||||
import hep.dataforge.plots.data.DataPlot
|
||||
import inr.numass.NumassPlugin
|
||||
import inr.numass.data.NumassDataUtils
|
||||
import inr.numass.data.analyzers.NumassAnalyzer
|
||||
import inr.numass.data.analyzers.SmartAnalyzer
|
||||
import inr.numass.data.api.NumassSet
|
||||
import inr.numass.data.storage.NumassStorageFactory
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
val context = buildContext("NUMASS", NumassPlugin::class.java, PlotManager::class.java) {
|
||||
rootDir = "D:\\Work\\Numass\\sterile2017_05"
|
||||
dataDir = "D:\\Work\\Numass\\data\\2017_05"
|
||||
}
|
||||
//val rootDir = File("D:\\Work\\Numass\\data\\2017_05\\Fill_2")
|
||||
|
||||
val storage = NumassStorageFactory.buildLocal(context, "Fill_2", true, false);
|
||||
|
||||
val sets = (2..14).map { "set_$it" }
|
||||
|
||||
val loaders = sets.mapNotNull { set ->
|
||||
storage.provide("loader::$set", NumassSet::class.java).orElse(null)
|
||||
}
|
||||
|
||||
val analyzer = SmartAnalyzer()
|
||||
|
||||
val all = NumassDataUtils.join("sum", loaders)
|
||||
|
||||
|
||||
val meta = buildMeta {
|
||||
"window.lo" to 400
|
||||
"window.up" to 1800
|
||||
}
|
||||
|
||||
val plots = context.getFeature(PlotManager::class.java)
|
||||
|
||||
val frame = plots.getPlotFrame("differential")
|
||||
|
||||
val integralFrame = plots.getPlotFrame("integral")
|
||||
|
||||
for (hv in arrayOf(14000.0, 14200.0, 14400.0, 14600.0, 14800.0, 15000.0)) {
|
||||
val point1 = all.optPoint(hv).get()
|
||||
|
||||
val point0 = all.optPoint(hv + 200.0).get()
|
||||
|
||||
with(NumassAnalyzer) {
|
||||
|
||||
val spectrum1 = analyzer.getSpectrum(point1, meta).withBinning(20)
|
||||
|
||||
val spectrum0 = analyzer.getSpectrum(point0, meta).withBinning(20)
|
||||
|
||||
val res = subtractAmplitudeSpectrum(spectrum1, spectrum0)
|
||||
|
||||
val norm = res.getColumn(COUNT_RATE_KEY).stream().mapToDouble { it.doubleValue() }.sum()
|
||||
|
||||
integralFrame.add(DataPlot.plot("point_$hv", AMPLITUDE_ADAPTER, spectrum0))
|
||||
|
||||
frame.add(DataPlot.plot("point_$hv", AMPLITUDE_ADAPTER, res.replaceColumn(COUNT_RATE_KEY) { getDouble(COUNT_RATE_KEY) / norm }))
|
||||
}
|
||||
}
|
||||
}
|
@ -30,16 +30,17 @@ import inr.numass.data.analyzers.TimeAnalyzer
|
||||
import inr.numass.data.analyzers.getSpectrum
|
||||
import inr.numass.data.api.NumassSet
|
||||
import inr.numass.data.storage.NumassStorageFactory
|
||||
import java.io.File
|
||||
import kotlin.streams.asSequence
|
||||
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
val context = buildContext("NUMASS", NumassPlugin::class.java, PlotManager::class.java)
|
||||
val rootDir = File("D:\\Work\\Numass\\data\\2017_05\\Fill_2")
|
||||
val context = buildContext("NUMASS", NumassPlugin::class.java, PlotManager::class.java){
|
||||
rootDir = "D:\\Work\\Numass\\sterile2017_05"
|
||||
}
|
||||
//val rootDir = File("D:\\Work\\Numass\\data\\2017_05\\Fill_2")
|
||||
|
||||
val storage = NumassStorageFactory.buildLocal(context, rootDir, true, false);
|
||||
val storage = NumassStorageFactory.buildLocal(context, "D:\\Work\\Numass\\data\\2017_05\\Fill_2", true, false);
|
||||
|
||||
val sets = (2..14).map { "set_$it" }
|
||||
|
||||
@ -99,9 +100,9 @@ fun main(args: Array<String>) {
|
||||
|
||||
|
||||
plots.getPlotFrame("amps").apply {
|
||||
add(DataPlot.plot("events", ADAPTER, events.replaceColumn(COUNT_RATE_KEY){getDouble(COUNT_RATE_KEY)/eventsNorming}))
|
||||
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}))
|
||||
add(DataPlot.plot("events", AMPLITUDE_ADAPTER, events.replaceColumn(COUNT_RATE_KEY){getDouble(COUNT_RATE_KEY)/eventsNorming}))
|
||||
add(DataPlot.plot("filtered", AMPLITUDE_ADAPTER, filtered.replaceColumn(COUNT_RATE_KEY){getDouble(COUNT_RATE_KEY)/filteredNorming}))
|
||||
add(DataPlot.plot("defaultFiltered", AMPLITUDE_ADAPTER, defaultFiltered.replaceColumn(COUNT_RATE_KEY){getDouble(COUNT_RATE_KEY)/defaultFilteredNorming}))
|
||||
}
|
||||
|
||||
// plots.getPlotFrame("ratio").apply {
|
||||
|
@ -31,7 +31,7 @@ import inr.numass.addSetMarkers
|
||||
import inr.numass.data.analyzers.SmartAnalyzer
|
||||
import inr.numass.data.api.NumassPoint
|
||||
import inr.numass.data.api.NumassSet
|
||||
import inr.numass.subtractAmplitudeSpectrum
|
||||
import inr.numass.subtractSpectrum
|
||||
import inr.numass.unbox
|
||||
import inr.numass.utils.ExpressionUtils
|
||||
import java.io.PrintWriter
|
||||
@ -170,7 +170,7 @@ val subtractEmptyTask = task("dif") {
|
||||
node("empty", empty.meta)
|
||||
}
|
||||
val res = DataUtils.combine(input, empty, Table::class.java, resMeta) { mergeData, emptyData ->
|
||||
subtractAmplitudeSpectrum(context, mergeData, emptyData)
|
||||
subtractSpectrum(mergeData, emptyData, context.logger)
|
||||
}
|
||||
|
||||
res.goal.onComplete { r, _ ->
|
||||
|
Loading…
Reference in New Issue
Block a user