Minor changes

This commit is contained in:
Alexander Nozik 2018-10-04 20:32:16 +03:00
parent 3383219da1
commit c1d421a84f
10 changed files with 251 additions and 13 deletions

View File

@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = "1.2.61"
ext.kotlin_version = "1.2.70"
repositories {
jcenter()
maven {

View File

@ -23,7 +23,7 @@ import hep.dataforge.meta.KMetaBuilder
import hep.dataforge.meta.buildMeta
import hep.dataforge.nullable
import hep.dataforge.plots.data.DataPlot
import hep.dataforge.plots.output.plot
import hep.dataforge.plots.output.plotFrame
import hep.dataforge.tables.Adapters
import inr.numass.data.analyzers.NumassAnalyzer
import inr.numass.data.analyzers.SimpleAnalyzer
@ -78,7 +78,7 @@ fun NumassBlock.plotAmplitudeSpectrum(plotName: String = "spectrum", frameName:
val lo = meta.optNumber("window.lo").nullable?.toInt()
val up = meta.optNumber("window.up").nullable?.toInt()
val data = SimpleAnalyzer().getAmplitudeSpectrum(this, meta.getMetaOrEmpty("spectrum")).withBinning(binning, lo, up)
context.plot(plotName) {
context.plotFrame(plotName) {
val valueAxis = if (meta.getBoolean("normalize", false)) {
NumassAnalyzer.COUNT_RATE_KEY
} else {

View File

@ -23,7 +23,7 @@ import hep.dataforge.meta.KMetaBuilder
import hep.dataforge.meta.buildMeta
import hep.dataforge.nullable
import hep.dataforge.plots.data.DataPlot
import hep.dataforge.plots.output.plot
import hep.dataforge.plots.output.plotFrame
import hep.dataforge.tables.Adapters
import inr.numass.data.analyzers.NumassAnalyzer
import inr.numass.data.analyzers.SmartAnalyzer
@ -37,7 +37,7 @@ fun NumassBlock.plotAmplitudeSpectrum(plotName: String = "spectrum", frameName:
val lo = meta.optNumber("window.lo").nullable?.toInt()
val up = meta.optNumber("window.up").nullable?.toInt()
val data = SmartAnalyzer().getAmplitudeSpectrum(this, meta.getMetaOrEmpty("spectrum")).withBinning(binning, lo, up)
context.plot(plotName) {
context.plotFrame(plotName) {
val valueAxis = if (meta.getBoolean("normalize", false)) {
NumassAnalyzer.COUNT_RATE_KEY
} else {

View File

@ -4,7 +4,7 @@ import hep.dataforge.context.Global
import hep.dataforge.maths.chain.Chain
import hep.dataforge.meta.buildMeta
import hep.dataforge.plots.data.XYFunctionPlot
import hep.dataforge.plots.output.plot
import hep.dataforge.plots.output.plotFrame
import hep.dataforge.stat.PolynomialDistribution
import hep.dataforge.stat.fit.ParamSet
import inr.numass.NumassPlugin
@ -46,7 +46,7 @@ fun main(args: Array<String>) {
50 * distribution.density(18600.0 - it)
}
Global.plot("beta") {
Global.plotFrame("beta") {
add(spectrumPlot)
add(distributionPlot)
}

View File

@ -124,7 +124,7 @@ object LossCalculator {
* @param X
* @return
*/
fun getLossProbabilities(x: Double): List<Double> {
fun calculateLossProbabilities(x: Double): List<Double> {
val res = ArrayList<Double>()
var prob: Double
if (x > 0) {
@ -151,6 +151,8 @@ object LossCalculator {
return res
}
fun getLossProbabilities(x: Double): List<Double> = lossProbCache.getOrPut(x) { calculateLossProbabilities(x) }
fun getLossProbability(order: Int, X: Double): Double {
if (order == 0) {
return if (X > 0) {

View File

@ -24,7 +24,7 @@ import hep.dataforge.meta.Meta
import hep.dataforge.plots.Plot
import hep.dataforge.plots.data.DataPlot
import hep.dataforge.plots.jfreechart.JFreeChartPlugin
import hep.dataforge.plots.output.plot
import hep.dataforge.plots.output.plotFrame
import hep.dataforge.stat.fit.FitManager
import hep.dataforge.stat.fit.FitStage
import hep.dataforge.stat.fit.FitState
@ -127,7 +127,7 @@ fun main(args: Array<String>) {
}
context.plot("fit", stage = "plots") {
context.plotFrame("fit", stage = "plots") {
plots.configure {
"showLine" to true
"showSymbol" to false

View File

@ -0,0 +1,66 @@
/*
* 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.api.NumassSet
import inr.numass.data.storage.NumassDirectory
import inr.numass.displayChart
import inr.numass.subthreshold.Threshold
fun main(args: Array<String>) {
val context = buildContext("NUMASS", NumassPlugin::class.java, JFreeChartPlugin::class.java) {
rootDir = "D:\\Work\\Numass\\sterile\\2017_05"
dataDir = "D:\\Work\\Numass\\data\\2017_05"
output = FXOutputManager() + DirectoryOutput()
}
val storage = NumassDirectory.read(context, "Fill_2") as? FileStorage ?: error("Storage not found")
val meta = buildMeta {
"delta" to -200
"method" to "pow"
"t0" to 15e3
"window.lo" to 400
"window.up" to 1600
}
val frame = displayChart("correction").apply {
plots.setType<DataPlot>()
}
listOf("set_2", "set_3", "set_4", "set_5").forEach { setName ->
val set = storage.provide(setName, NumassSet::class.java).nullable ?: error("Set does not exist")
val correctionTable = Threshold.calculateSubThreshold(set, meta).filter {
it.getDouble("correction") in (1.0..1.2)
}
frame.plotData(setName, correctionTable, Adapters.buildXYAdapter("U", "correction"))
}
}

View File

@ -0,0 +1,162 @@
/*
* 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.tristan
import hep.dataforge.buildContext
import hep.dataforge.configure
import hep.dataforge.data.DataNode
import hep.dataforge.fx.output.FXOutputManager
import hep.dataforge.io.ColumnedDataReader
import hep.dataforge.io.DirectoryOutput
import hep.dataforge.io.output.stream
import hep.dataforge.io.plus
import hep.dataforge.meta.Meta
import hep.dataforge.meta.buildMeta
import hep.dataforge.plots.data.DataPlot
import hep.dataforge.plots.jfreechart.JFreeChartPlugin
import hep.dataforge.plots.output.plotFrame
import hep.dataforge.stat.fit.FitHelper
import hep.dataforge.stat.fit.ParamSet
import hep.dataforge.tables.*
import hep.dataforge.values.ValueType
import inr.numass.NumassPlugin
import inr.numass.actions.MergeDataAction
import inr.numass.data.analyzers.NumassAnalyzer.Companion.COUNT_KEY
import inr.numass.data.analyzers.NumassAnalyzer.Companion.COUNT_RATE_ERROR_KEY
import inr.numass.data.analyzers.NumassAnalyzer.Companion.COUNT_RATE_KEY
import inr.numass.data.analyzers.NumassAnalyzer.Companion.LENGTH_KEY
import inr.numass.data.api.NumassPoint.Companion.HV_KEY
import java.io.PrintWriter
import java.nio.file.Files
import java.util.function.Predicate
fun main(args: Array<String>) {
val context = buildContext("NUMASS") {
plugin<NumassPlugin>()
plugin<JFreeChartPlugin>()
rootDir = "D:\\Work\\Numass\\TristanText\\"
dataDir = "D:\\Work\\Numass\\TristanText\\data\\"
output = FXOutputManager() + DirectoryOutput()
}
context.load<NumassPlugin>()
val tables = DataNode.build<Table> {
name = "tristan"
Files.list(context.dataDir).forEach {
val name = ".*(set_\\d+).*".toRegex().matchEntire(it.fileName.toString())!!.groupValues[1]
val table = ColumnedDataReader(Files.newInputStream(it), HV_KEY, COUNT_RATE_KEY, COUNT_RATE_ERROR_KEY).toTable()
.addColumn(LENGTH_KEY, ValueType.NUMBER) { 30 }
.addColumn(COUNT_KEY, ValueType.NUMBER) { getDouble(COUNT_RATE_KEY) * 30 }
putStatic(name, table)
}
}
val adapter = Adapters.buildXYAdapter(HV_KEY, COUNT_RATE_KEY, COUNT_RATE_ERROR_KEY)
context.plotFrame("raw", "plots") {
configure {
"legend.show" to false
}
plots.configure {
"showLine" to true
"showSymbol" to false
}
tables.forEach { (key, value) ->
add(DataPlot.plot(key, value, adapter))
}
}
context.plotFrame("raw_normalized", "plots") {
configure {
"legend.show" to false
}
plots.configure {
"showLine" to true
"showSymbol" to false
}
tables.forEach { (key, table) ->
val norming = table.find { it.getDouble(HV_KEY) == 13000.0 }!!.getDouble(COUNT_RATE_KEY)
val normalizedTable = table
.replaceColumn(COUNT_RATE_KEY) { getDouble(COUNT_RATE_KEY) / norming }
.replaceColumn(COUNT_RATE_ERROR_KEY) { getDouble(COUNT_RATE_ERROR_KEY) / norming }
add(DataPlot.plot(key, normalizedTable, adapter))
}
}
val merge = MergeDataAction.runGroup(context, tables, Meta.empty()).get()
val filtered = Tables.filter(merge,
Predicate {
val hv = it.getDouble(HV_KEY)
hv > 12200.0 && (hv < 15500 || hv > 16500)
}
)
context.plotFrame("merge", "plots") {
plots.configure {
"showLine" to true
"showSymbol" to false
}
add(DataPlot.plot("merge", merge, adapter))
}
val meta = buildMeta {
"model" to {
"modelName" to "sterile"
"resolution" to {
"width" to 8.3e-5
"tail" to "function::numass.resolutionTail.2017.mod"
}
"transmission" to {
"trapping" to "function::numass.trap.nominal"
}
}
"stage" to { "freePars" to listOf("N", "bkg", "E0") }
}
val params = ParamSet().apply {
setPar("N", 4e4, 6.0, 0.0, Double.POSITIVE_INFINITY)
setPar("bkg", 2.0, 0.03)
setPar("E0", 18575.0, 1.0)
setPar("mnu2", 0.0, 1.0)
setParValue("msterile2", (1000 * 1000).toDouble())
setPar("U2", 0.0, 1e-3)
setPar("X", 0.1, 0.01)
setPar("trap", 1.0, 0.01)
}
context.output["numass.fit", "text"].stream.use { out ->
val log = context.history.getChronicle("log")
val writer = PrintWriter(out)
writer.printf("%n*** META ***%n")
writer.println(meta.toString())
writer.flush()
FitHelper(context)
.fit(filtered, meta)
.setListenerStream(out)
.report(log)
.apply {
params(params)
}.run()
writer.println()
log.entries.forEach { entry -> writer.println(entry.toString()) }
writer.println()
}
}

View File

@ -11,11 +11,14 @@ import hep.dataforge.tables.ListTable
import hep.dataforge.tables.Table
import hep.dataforge.values.ValueMap
import hep.dataforge.values.Values
import inr.numass.data.analyzers.NumassAnalyzer
import inr.numass.data.analyzers.NumassAnalyzer.Companion.CHANNEL_KEY
import inr.numass.data.analyzers.NumassAnalyzer.Companion.COUNT_RATE_KEY
import inr.numass.data.analyzers.SmartAnalyzer
import inr.numass.data.analyzers.TimeAnalyzer
import inr.numass.data.analyzers.withBinning
import inr.numass.data.api.NumassPoint
import inr.numass.data.api.NumassSet
import inr.numass.data.api.SimpleNumassPoint
import inr.numass.data.storage.NumassDataLoader
import inr.numass.data.storage.NumassDirectory
@ -137,6 +140,7 @@ object Threshold {
}
/**
* Exponential function $a e^{\frac{x}{\sigma}}$
*/
@ -226,9 +230,12 @@ object Threshold {
}
}
fun calculateSubThreshold(spectra: Map<Double, Table>, config: Meta): Table {
fun calculateSubThreshold(set: NumassSet, config: Meta, analyzer: NumassAnalyzer = SmartAnalyzer()): Table {
return ListTable.Builder().apply {
spectra.forEach { voltage, spectrum -> row(calculateSubThreshold(spectrum, voltage, config)) }
set.forEach{
val spectrum = analyzer.getAmplitudeSpectrum(it,config)
row(calculateSubThreshold(spectrum,it.voltage,config))
}
}.build()
}

View File

@ -16,6 +16,7 @@ import hep.dataforge.plots.data.XYFunctionPlot
import hep.dataforge.plots.jfreechart.JFreeChartFrame
import hep.dataforge.plots.output.PlotOutput
import hep.dataforge.plots.output.plot
import hep.dataforge.plots.output.plotFrame
import hep.dataforge.stat.fit.FitHelper
import hep.dataforge.stat.fit.FitResult
import hep.dataforge.stat.models.XYModel
@ -351,7 +352,7 @@ val histogramTask = task("histogram") {
context.output.render(table, stage = "numass.histogram", name = name, meta = meta)
if (meta.getBoolean("plot", false)) {
context.plot("$name.plot", stage = "numass.histogram") {
context.plotFrame("$name.plot", stage = "numass.histogram") {
plots.setType<DataPlot>()
plots.configure {
"showSymbol" to false