Fix fx plugins
This commit is contained in:
parent
f376fa65a4
commit
6e62b57e0d
@ -14,7 +14,10 @@ import java.security.MessageDigest
|
||||
/**
|
||||
* Dynamic workspace that is parsed from file using external algorithm. Workspace is reloaded only if file is changed
|
||||
*/
|
||||
class FileBasedWorkspace(private val path: Path, private val parser: (Path) -> Workspace) : DynamicWorkspace(), AutoCloseable {
|
||||
class FileBasedWorkspace(
|
||||
private val path: Path,
|
||||
private val parser: (Path) -> Workspace
|
||||
) : DynamicWorkspace(), AutoCloseable {
|
||||
|
||||
private var watchJob: Job? = null
|
||||
|
||||
@ -69,7 +72,11 @@ class FileBasedWorkspace(private val path: Path, private val parser: (Path) -> W
|
||||
*/
|
||||
@JvmOverloads
|
||||
@JvmStatic
|
||||
fun build(context: Context, path: Path, transformation: (Workspace.Builder) -> Workspace = { it.build() }): FileBasedWorkspace {
|
||||
fun build(
|
||||
context: Context,
|
||||
path: Path,
|
||||
transformation: (Workspace.Builder) -> Workspace = { it.build() }
|
||||
): FileBasedWorkspace {
|
||||
val fileName = path.fileName.toString()
|
||||
return context.serviceStream(WorkspaceParser::class.java)
|
||||
.filter { parser -> parser.listExtensions().stream().anyMatch { fileName.endsWith(it) } }
|
||||
|
@ -1,9 +1,15 @@
|
||||
plugins{
|
||||
id "application"
|
||||
id "com.github.johnrengelman.shadow"
|
||||
id "org.openjfx.javafxplugin"
|
||||
}
|
||||
apply plugin: 'kotlin'
|
||||
|
||||
javafx {
|
||||
modules = ["javafx.controls", "javafx.web"]
|
||||
version = "11"
|
||||
}
|
||||
|
||||
if (!hasProperty('mainClass')) {
|
||||
ext.mainClass = 'hep.dataforge.plots.demo.DemoApp'//"inr.numass.viewer.test.TestApp"
|
||||
}
|
||||
|
@ -1,16 +0,0 @@
|
||||
//apply plugin: 'org.openjfx.javafxplugin'
|
||||
//
|
||||
//javafx {
|
||||
// modules = [ 'javafx.controls' ]
|
||||
//}
|
||||
|
||||
|
||||
description = 'jFreeChart plugin'
|
||||
|
||||
dependencies {
|
||||
api 'org.jfree:jfreesvg:3.3'
|
||||
// https://mvnrepository.com/artifact/org.jfree/jfreechart-fx
|
||||
api group: 'org.jfree', name: 'jfreechart-fx', version: '1.0.1'
|
||||
|
||||
api project(":dataforge-plots")
|
||||
}
|
19
dataforge-plots/plots-jfc/build.gradle.kts
Normal file
19
dataforge-plots/plots-jfc/build.gradle.kts
Normal file
@ -0,0 +1,19 @@
|
||||
plugins {
|
||||
id("org.openjfx.javafxplugin")
|
||||
}
|
||||
|
||||
javafx {
|
||||
modules = listOf("javafx.controls")
|
||||
version = "11"
|
||||
}
|
||||
|
||||
description = "jFreeChart plugin"
|
||||
|
||||
dependencies {
|
||||
api("org.jfree:jfreesvg:3.4.2")
|
||||
// https://mvnrepository.com/artifact/org.jfree/org.jfree.chart.fx
|
||||
api(group= "org.jfree", name= "jfreechart-fx", version= "1.0.1")
|
||||
|
||||
|
||||
api(project(":dataforge-plots"))
|
||||
}
|
@ -1,6 +1,12 @@
|
||||
plugins {
|
||||
id "com.github.johnrengelman.shadow"
|
||||
id 'application'
|
||||
id "org.openjfx.javafxplugin"
|
||||
}
|
||||
|
||||
javafx {
|
||||
modules = ["javafx.controls", "javafx.web"]
|
||||
version = "11"
|
||||
}
|
||||
|
||||
apply plugin: "kotlin"
|
||||
|
@ -2,6 +2,12 @@ plugins {
|
||||
id 'groovy'
|
||||
id 'application'
|
||||
id "com.github.johnrengelman.shadow"
|
||||
id "org.openjfx.javafxplugin"
|
||||
}
|
||||
|
||||
javafx {
|
||||
modules = ["javafx.controls", "javafx.web"]
|
||||
version = "11"
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,3 +1,13 @@
|
||||
plugins {
|
||||
id("org.openjfx.javafxplugin")
|
||||
}
|
||||
|
||||
javafx {
|
||||
modules = ["javafx.controls", "javafx.web"]
|
||||
version = "11"
|
||||
}
|
||||
|
||||
|
||||
dependencies {
|
||||
api project(':dataforge-plots:plots-jfc')
|
||||
api project(':dataforge-control')
|
||||
|
@ -1,3 +1,13 @@
|
||||
|
||||
plugins{
|
||||
id "org.openjfx.javafxplugin"
|
||||
}
|
||||
|
||||
javafx {
|
||||
modules = ["javafx.controls", "javafx.web"]
|
||||
version = "11"
|
||||
}
|
||||
|
||||
apply plugin: 'application'
|
||||
apply plugin: 'kotlin'
|
||||
|
||||
|
@ -1,17 +1,15 @@
|
||||
//
|
||||
//plugins {
|
||||
// id 'application'
|
||||
// id 'org.openjfx.javafxplugin' version '0.0.5'
|
||||
//}
|
||||
//
|
||||
//javafx {
|
||||
// modules = [ 'javafx.controls' ]
|
||||
//}
|
||||
|
||||
plugins{
|
||||
id 'application'
|
||||
id "org.openjfx.javafxplugin"
|
||||
}
|
||||
|
||||
javafx {
|
||||
modules = ["javafx.controls", "javafx.web"]
|
||||
version = "11"
|
||||
}
|
||||
|
||||
|
||||
version = "0.1.0"
|
||||
|
||||
if (!hasProperty('mainClass')) {
|
||||
|
@ -1,4 +1,13 @@
|
||||
apply plugin: 'application'
|
||||
|
||||
plugins{
|
||||
id 'application'
|
||||
id "org.openjfx.javafxplugin"
|
||||
}
|
||||
|
||||
javafx {
|
||||
modules = ["javafx.controls", "javafx.web"]
|
||||
version = "11"
|
||||
}
|
||||
|
||||
version = "0.3.0"
|
||||
|
||||
|
@ -1,4 +1,12 @@
|
||||
apply plugin: 'application'
|
||||
plugins{
|
||||
id 'application'
|
||||
id "org.openjfx.javafxplugin"
|
||||
}
|
||||
|
||||
javafx {
|
||||
modules = ["javafx.controls", "javafx.web"]
|
||||
version = "11"
|
||||
}
|
||||
|
||||
version = "0.4.0"
|
||||
|
||||
|
@ -1,4 +1,12 @@
|
||||
apply plugin: 'application'
|
||||
plugins{
|
||||
id 'application'
|
||||
id "org.openjfx.javafxplugin"
|
||||
}
|
||||
|
||||
javafx {
|
||||
modules = ["javafx.controls", "javafx.web"]
|
||||
version = "11"
|
||||
}
|
||||
|
||||
version = "0.6.0"
|
||||
|
||||
|
@ -81,9 +81,9 @@ class MeradatVacDevice(context: Context, meta: Meta) : PortSensor(context, meta)
|
||||
* String is Hex String, need to convert in ASCII.
|
||||
*/
|
||||
val bytes = BigInteger(inputString, 16).toByteArray()
|
||||
val checksum = bytes.sumBy { it.toInt() }
|
||||
val checksum = bytes.sumOf { it.toInt() }
|
||||
var value = Integer.toHexString(-checksum)
|
||||
value = value.substring(value.length - 2).toUpperCase()
|
||||
value = value.substring(value.length - 2).uppercase()
|
||||
if (value.length < 2) {
|
||||
value = "0$value"
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ class ThyroContVacDevice(context: Context, meta: Meta) : PortSensor(context, met
|
||||
return GenericPortController(context, port) { it.endsWith("\r") }
|
||||
}
|
||||
|
||||
private fun String.checksum(): Char = (sumBy { it.code } % 64 + 64).toChar()
|
||||
private fun String.checksum(): Char = (sumOf { it.code } % 64 + 64).toChar()
|
||||
|
||||
private fun wrap(str: String): String = buildString {
|
||||
append(str)
|
||||
|
@ -59,7 +59,7 @@ abstract class AbstractAnalyzer @JvmOverloads constructor(private val processor:
|
||||
protected fun getAllEvents(block: NumassBlock): Stream<NumassEvent> {
|
||||
return when {
|
||||
block.frames.count() == 0L -> block.events
|
||||
processor == null -> throw IllegalArgumentException("Signal processor needed to analyze frames")
|
||||
processor == null -> block.events//throw IllegalArgumentException("Signal processor needed to analyze frames")
|
||||
else -> Stream.concat(block.events, block.frames.flatMap { processor.process(block, it) })
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,12 @@
|
||||
plugins {
|
||||
id 'groovy'
|
||||
id 'application'
|
||||
id "org.openjfx.javafxplugin"
|
||||
}
|
||||
|
||||
javafx {
|
||||
modules = ["javafx.controls", "javafx.web"]
|
||||
version = "11"
|
||||
}
|
||||
|
||||
apply plugin: 'kotlin'
|
||||
|
@ -0,0 +1,29 @@
|
||||
package inr.numass.scripts.analysis
|
||||
|
||||
import hep.dataforge.context.Global
|
||||
import hep.dataforge.fx.output.FXOutputManager
|
||||
import hep.dataforge.plots.jfreechart.JFreeChartPlugin
|
||||
import inr.numass.data.ProtoNumassPoint
|
||||
import java.io.File
|
||||
|
||||
fun main() {
|
||||
Global.output = FXOutputManager()
|
||||
JFreeChartPlugin().startGlobal()
|
||||
|
||||
val file = File("C:\\Users\\darksnake\\Desktop\\test-data\\p20211012142003(20s)").toPath()
|
||||
val point = ProtoNumassPoint.readFile(file)
|
||||
|
||||
point.events.forEach {
|
||||
println("channel: ${it.owner.channel}, startTime: ${it.owner.startTime} timeOffset: ${it.timeOffset}\t amp: ${it.amplitude}")
|
||||
}
|
||||
|
||||
// Global.plotFrame("compare") {
|
||||
// plotAmplitudeSpectrum(point, "cut") {
|
||||
// "t0" to 3e3
|
||||
// "sortEvents" to true
|
||||
// }
|
||||
// plotAmplitudeSpectrum(point, "uncut")
|
||||
// }
|
||||
//
|
||||
// readLine()
|
||||
}
|
@ -18,6 +18,7 @@ package inr.numass.scripts.models
|
||||
|
||||
import hep.dataforge.buildContext
|
||||
import hep.dataforge.configure
|
||||
import hep.dataforge.data.NamedData
|
||||
import hep.dataforge.fx.FXPlugin
|
||||
import hep.dataforge.fx.output.FXOutputManager
|
||||
import hep.dataforge.meta.Meta
|
||||
@ -26,23 +27,23 @@ import hep.dataforge.plots.data.DataPlot
|
||||
import hep.dataforge.plots.jfreechart.JFreeChartPlugin
|
||||
import hep.dataforge.plots.output.plotFrame
|
||||
import hep.dataforge.plots.plotFunction
|
||||
import hep.dataforge.stat.fit.FitHelper
|
||||
import hep.dataforge.stat.fit.FitManager
|
||||
import hep.dataforge.stat.fit.FitStage
|
||||
import hep.dataforge.stat.fit.FitState
|
||||
import hep.dataforge.stat.fit.ParamSet
|
||||
import hep.dataforge.stat.models.XYModel
|
||||
import hep.dataforge.step
|
||||
import hep.dataforge.tables.Adapters.X_AXIS
|
||||
import hep.dataforge.tables.Adapters
|
||||
import hep.dataforge.tables.Table
|
||||
import hep.dataforge.values.ValueMap
|
||||
import hep.dataforge.workspace.FileBasedWorkspace
|
||||
import inr.numass.NumassPlugin
|
||||
import inr.numass.data.SpectrumAdapter
|
||||
import inr.numass.data.SpectrumGenerator
|
||||
import inr.numass.data.analyzers.NumassAnalyzer
|
||||
import inr.numass.data.api.NumassPoint
|
||||
import inr.numass.models.NBkgSpectrum
|
||||
import inr.numass.models.sterile.NumassResolution
|
||||
import inr.numass.models.sterile.SterileNeutrinoSpectrum
|
||||
import org.apache.commons.math3.analysis.interpolation.SplineInterpolator
|
||||
import java.io.PrintWriter
|
||||
import java.io.File
|
||||
|
||||
private fun getCustomResolution(): NumassResolution {
|
||||
val correctionDataString = """
|
||||
@ -84,16 +85,19 @@ fun main() {
|
||||
JFreeChartPlugin::class.java
|
||||
) {
|
||||
output = FXOutputManager()
|
||||
properties {
|
||||
setValue("cache.enabled", false)
|
||||
}
|
||||
}
|
||||
|
||||
val params = ParamSet().apply {
|
||||
setPar("N", 8e5, 6.0, 0.0, Double.POSITIVE_INFINITY)
|
||||
setPar("bkg", 2.0, 0.03)
|
||||
setPar("N", 8e5, 1e4, 0.0, Double.POSITIVE_INFINITY)
|
||||
setPar("bkg", 3.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.0, 0.01)
|
||||
setPar("X", 0.1, 0.01)
|
||||
setPar("trap", 1.0, 0.01)
|
||||
}
|
||||
|
||||
@ -122,36 +126,63 @@ fun main() {
|
||||
|
||||
val t = 30 * 50 // time in seconds per point
|
||||
|
||||
val adapter = SpectrumAdapter(Meta.empty())
|
||||
val adapter = Adapters.buildXYAdapter(
|
||||
NumassPoint.HV_KEY,
|
||||
NumassAnalyzer.COUNT_RATE_KEY,
|
||||
NumassAnalyzer.COUNT_RATE_ERROR_KEY
|
||||
)
|
||||
|
||||
val fm = context.getOrLoad(FitManager::class.java)
|
||||
val x = (14000.0..18500.0).step(100.0).toList()
|
||||
val dataModel = XYModel(Meta.empty(), adapter, dataSpectrum)
|
||||
|
||||
val generator = SpectrumGenerator(dataModel, params, 12316)
|
||||
|
||||
val configuration = x.map { ValueMap.ofPairs(X_AXIS to it, "time" to t) }
|
||||
val data: Table = generator.generateData(configuration)
|
||||
// define the data model
|
||||
val modifiedModel = XYModel(Meta.empty(), adapter, dataSpectrum)
|
||||
|
||||
// // Simulating data via model
|
||||
// val generator = SpectrumGenerator(dataModel, params, 12316)
|
||||
// val configuration = x.map { ValueMap.ofPairs(X_AXIS to it, "time" to t) }
|
||||
// val simulatedData: Table = generator.generateData(configuration)
|
||||
//
|
||||
// // Creating a model which does not know about distortion
|
||||
val modelSpectrum = NBkgSpectrum(SterileNeutrinoSpectrum(context, Meta.empty(), resolution = NumassResolution()))
|
||||
val fitModel = XYModel(Meta.empty(), adapter, modelSpectrum)
|
||||
//
|
||||
// context.plotFrame("fit", stage = "plots") {
|
||||
// plots.configure {
|
||||
// "showLine" to true
|
||||
// "showSymbol" to false
|
||||
// "showErrors" to false
|
||||
// "thickness" to 4.0
|
||||
// }
|
||||
// plots.setType<DataPlot>()
|
||||
// +dataModel.plot("Data", params)
|
||||
// +fitModel.plot("Fit-start", params)
|
||||
// }
|
||||
//
|
||||
// //fitting
|
||||
// val state = FitState(simulatedData, fitModel, params)
|
||||
// val res = fm.runStage(state, "QOW", FitStage.TASK_RUN, "N", "E0", "bkg")
|
||||
// res.printState(PrintWriter(System.out))
|
||||
// val resWithTrap = fm.runStage(state, "QOW", FitStage.TASK_RUN, "N", "E0", "bkg", "trap")
|
||||
// resWithTrap.printState(PrintWriter(System.out))
|
||||
// val resWithU2 = fm.runStage(resWithTrap.optState().get(), "QOW", FitStage.TASK_RUN, "N", "E0", "bkg", "trap", "U2")
|
||||
// resWithU2.printState(PrintWriter(System.out))
|
||||
|
||||
context.plotFrame("fit", stage = "plots") {
|
||||
plots.configure {
|
||||
"showLine" to true
|
||||
"showSymbol" to false
|
||||
"showErrors" to false
|
||||
"thickness" to 4.0
|
||||
}
|
||||
plots.setType<DataPlot>()
|
||||
+dataModel.plot("Data", params)
|
||||
+fitModel.plot("Fit-start", params)
|
||||
}
|
||||
// loading real data
|
||||
val configPath = File("D:\\Work\\Numass\\sterile2017_11\\workspace.groovy").toPath()
|
||||
val workspace = FileBasedWorkspace.build(context, configPath)
|
||||
|
||||
val data = workspace.runTask("filter", "fill_2").first() as NamedData<Table>
|
||||
val table = data.get()
|
||||
|
||||
//fitting
|
||||
FitHelper(context).fit(table).apply {
|
||||
model(modifiedModel)
|
||||
report("fit")
|
||||
params(params)
|
||||
stage("QOW", FitStage.TASK_RUN, "N", "E0", "bkg")
|
||||
stage("QOW", FitStage.TASK_RUN, "N", "E0", "bkg", "trap")
|
||||
stage("QOW", FitStage.TASK_RUN, "N", "E0", "bkg", "trap", "U2")
|
||||
}.run()
|
||||
|
||||
val state = FitState(data, fitModel, params)
|
||||
val res = fm.runStage(state, "QOW", FitStage.TASK_RUN, "N", "E0", "bkg")
|
||||
res.printState(PrintWriter(System.out))
|
||||
val resWithTrap = fm.runStage(state, "QOW", FitStage.TASK_RUN, "N", "E0", "bkg", "trap")
|
||||
resWithTrap.printState(PrintWriter(System.out))
|
||||
val resWithU2 = fm.runStage(resWithTrap.optState().get(), "QOW", FitStage.TASK_RUN, "N", "E0", "bkg", "trap", "U2")
|
||||
resWithU2.printState(PrintWriter(System.out))
|
||||
}
|
Loading…
Reference in New Issue
Block a user