Fix to task generics.
This commit is contained in:
parent
57650d6512
commit
d6b93d67e5
@ -18,7 +18,7 @@ package inr.numass.control.dante
|
||||
|
||||
import hep.dataforge.context.Context
|
||||
import hep.dataforge.context.Global
|
||||
import hep.dataforge.fx.plots.display
|
||||
import hep.dataforge.fx.plots.displayPlot
|
||||
import hep.dataforge.kodex.configure
|
||||
import hep.dataforge.kodex.nullable
|
||||
import hep.dataforge.meta.KMetaBuilder
|
||||
@ -79,29 +79,30 @@ 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.display(
|
||||
chart {
|
||||
val valueAxis = if (meta.getBoolean("normalize", false)) {
|
||||
NumassAnalyzer.COUNT_RATE_KEY
|
||||
} else {
|
||||
NumassAnalyzer.COUNT_KEY
|
||||
}
|
||||
plots.configure {
|
||||
"connectionType" to "step"
|
||||
"thickness" to 2
|
||||
"showLine" to true
|
||||
"showSymbol" to false
|
||||
"showErrors" to false
|
||||
}.setType(DataPlot::class)
|
||||
|
||||
val plot = DataPlot.plot(
|
||||
plotName,
|
||||
Adapters.buildXYAdapter(NumassAnalyzer.CHANNEL_KEY, valueAxis),
|
||||
data
|
||||
)
|
||||
plot.configure(meta)
|
||||
add(plot)
|
||||
context.displayPlot {
|
||||
chart {
|
||||
val valueAxis = if (meta.getBoolean("normalize", false)) {
|
||||
NumassAnalyzer.COUNT_RATE_KEY
|
||||
} else {
|
||||
NumassAnalyzer.COUNT_KEY
|
||||
}
|
||||
)
|
||||
plots.configure {
|
||||
"connectionType" to "step"
|
||||
"thickness" to 2
|
||||
"showLine" to true
|
||||
"showSymbol" to false
|
||||
"showErrors" to false
|
||||
}.setType<DataPlot>()
|
||||
|
||||
val plot = DataPlot.plot(
|
||||
plotName,
|
||||
data,
|
||||
Adapters.buildXYAdapter(NumassAnalyzer.CHANNEL_KEY, valueAxis)
|
||||
)
|
||||
plot.configure(meta)
|
||||
add(plot)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -70,7 +70,8 @@ class NumassPlugin : BasicPlugin() {
|
||||
transformTask,
|
||||
filterTask,
|
||||
fitTask,
|
||||
plotFitTask
|
||||
plotFitTask,
|
||||
histogramTask
|
||||
)
|
||||
|
||||
@Provides(Task.TASK_TARGET)
|
||||
|
@ -68,7 +68,7 @@ object PlotFitResultAction : OneToOneAction<FitResult, FitResult>() {
|
||||
StreamSupport.stream(data.spliterator(), false)
|
||||
.map { dp -> Adapters.getXValue(adapter, dp).double }.sorted().forEach{ fit.calculateIn(it) }
|
||||
|
||||
context.plot(listOf(fit,DataPlot.plot("data", adapter, data)), this.name, name)
|
||||
context.plot(listOf(fit,DataPlot.plot("data", data, adapter)), this.name, name)
|
||||
|
||||
return input
|
||||
}
|
||||
|
@ -18,13 +18,13 @@ package inr.numass.data
|
||||
|
||||
import hep.dataforge.context.Context
|
||||
import hep.dataforge.context.Global
|
||||
import hep.dataforge.fx.plots.display
|
||||
import hep.dataforge.fx.plots.displayPlot
|
||||
import hep.dataforge.kodex.configure
|
||||
import hep.dataforge.kodex.nullable
|
||||
import hep.dataforge.meta.KMetaBuilder
|
||||
import hep.dataforge.meta.buildMeta
|
||||
import hep.dataforge.plots.data.DataPlot
|
||||
import hep.dataforge.plots.jfreechart.JFreeChartFrame
|
||||
import hep.dataforge.plots.jfreechart.chart
|
||||
import hep.dataforge.tables.Adapters
|
||||
import inr.numass.data.analyzers.NumassAnalyzer
|
||||
import inr.numass.data.analyzers.SmartAnalyzer
|
||||
@ -38,8 +38,8 @@ 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.display {
|
||||
JFreeChartFrame().apply {
|
||||
context.displayPlot {
|
||||
chart {
|
||||
val valueAxis = if (meta.getBoolean("normalize", false)) {
|
||||
NumassAnalyzer.COUNT_RATE_KEY
|
||||
} else {
|
||||
@ -55,8 +55,8 @@ fun NumassBlock.plotAmplitudeSpectrum(plotName: String = "spectrum", frameName:
|
||||
|
||||
val plot = DataPlot.plot(
|
||||
plotName,
|
||||
Adapters.buildXYAdapter(NumassAnalyzer.CHANNEL_KEY, valueAxis),
|
||||
data
|
||||
data,
|
||||
Adapters.buildXYAdapter(NumassAnalyzer.CHANNEL_KEY, valueAxis)
|
||||
)
|
||||
plot.configure(meta)
|
||||
add(plot)
|
||||
|
@ -1,7 +1,7 @@
|
||||
package inr.numass.models.mc
|
||||
|
||||
import hep.dataforge.context.Global
|
||||
import hep.dataforge.fx.plots.display
|
||||
import hep.dataforge.fx.plots.displayPlot
|
||||
import hep.dataforge.maths.chain.Chain
|
||||
import hep.dataforge.meta.buildMeta
|
||||
import hep.dataforge.plots.XYFunctionPlot
|
||||
@ -47,7 +47,7 @@ fun main(args: Array<String>) {
|
||||
50 * distribution.density(18600.0 - it)
|
||||
}
|
||||
|
||||
Global.display {
|
||||
Global.displayPlot {
|
||||
chart {
|
||||
add(spectrumPlot)
|
||||
add(distributionPlot)
|
||||
|
@ -72,8 +72,8 @@ fun main(args: Array<String>) {
|
||||
|
||||
val point = set.optPoint(hv).get()
|
||||
|
||||
frame.add(DataPlot.plot("raw", AMPLITUDE_ADAPTER, analyzer.getAmplitudeSpectrum(point, meta).withBinning(20)))
|
||||
frame.add(DataPlot.plot("filtered", AMPLITUDE_ADAPTER, analyzer.getAmplitudeSpectrum(point, metaForChain).withBinning(20)))
|
||||
frame.add(DataPlot.plot("invertedFilter", AMPLITUDE_ADAPTER, analyzer.getAmplitudeSpectrum(point, metaForChainInverted).withBinning(20)))
|
||||
frame.add(DataPlot.plot("raw", analyzer.getAmplitudeSpectrum(point, meta).withBinning(20), AMPLITUDE_ADAPTER))
|
||||
frame.add(DataPlot.plot("filtered", analyzer.getAmplitudeSpectrum(point, metaForChain).withBinning(20), AMPLITUDE_ADAPTER))
|
||||
frame.add(DataPlot.plot("invertedFilter", analyzer.getAmplitudeSpectrum(point, metaForChainInverted).withBinning(20), AMPLITUDE_ADAPTER))
|
||||
}
|
||||
}
|
||||
|
@ -51,8 +51,8 @@ fun main(args: Array<String>) {
|
||||
this.plots.configureValue("showLine", true)
|
||||
}
|
||||
|
||||
frame.add(DataPlot.plot("raw", AMPLITUDE_ADAPTER, analyzer.getAmplitudeSpectrum(point, meta).withBinning(80)))
|
||||
frame.add(DataPlot.plot("filtered", AMPLITUDE_ADAPTER, analyzer.getAmplitudeSpectrum(point, metaForChain).withBinning(80)))
|
||||
frame.add(DataPlot.plot("invertedFilter", AMPLITUDE_ADAPTER, analyzer.getAmplitudeSpectrum(point, metaForChainInverted).withBinning(80)))
|
||||
frame.add(DataPlot.plot("raw", analyzer.getAmplitudeSpectrum(point, meta).withBinning(80), AMPLITUDE_ADAPTER))
|
||||
frame.add(DataPlot.plot("filtered", analyzer.getAmplitudeSpectrum(point, metaForChain).withBinning(80), AMPLITUDE_ADAPTER))
|
||||
frame.add(DataPlot.plot("invertedFilter", analyzer.getAmplitudeSpectrum(point, metaForChainInverted).withBinning(80), AMPLITUDE_ADAPTER))
|
||||
|
||||
}
|
||||
|
@ -81,9 +81,9 @@ fun main(args: Array<String>) {
|
||||
|
||||
val norm = res.getColumn(COUNT_RATE_KEY).stream().mapToDouble { it.double }.sum()
|
||||
|
||||
integralFrame.add(DataPlot.plot("point_$hv", AMPLITUDE_ADAPTER, spectrum0))
|
||||
integralFrame.add(DataPlot.plot("point_$hv", spectrum0, AMPLITUDE_ADAPTER))
|
||||
|
||||
frame.add(DataPlot.plot("point_$hv", AMPLITUDE_ADAPTER, res.replaceColumn(COUNT_RATE_KEY) { getDouble(COUNT_RATE_KEY) / norm }))
|
||||
frame.add(DataPlot.plot("point_$hv", res.replaceColumn(COUNT_RATE_KEY) { getDouble(COUNT_RATE_KEY) / norm }, AMPLITUDE_ADAPTER))
|
||||
}
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ import inr.numass.NumassUtils
|
||||
* @author Alexander Nozik
|
||||
*/
|
||||
object NumassFitScanSummaryTask : AbstractTask<Table>(Table::class.java) {
|
||||
override fun run(model: TaskModel, data: DataNode<*>): DataNode<Table> {
|
||||
override fun run(model: TaskModel, data: DataNode<Any>): DataNode<Table> {
|
||||
val builder = DataSet.edit(Table::class)
|
||||
val action = FitSummaryAction()
|
||||
val input = data.checked(FitResult::class.java)
|
||||
|
@ -24,7 +24,7 @@ import hep.dataforge.workspace.tasks.TaskModel
|
||||
*/
|
||||
object NumassFitScanTask : AbstractTask<FitResult>(FitResult::class.java) {
|
||||
|
||||
override fun run(model: TaskModel, data: DataNode<*>): DataNode<FitResult> {
|
||||
override fun run(model: TaskModel, data: DataNode<Any>): DataNode<FitResult> {
|
||||
val config = model.meta
|
||||
val scanParameter = config.getString("parameter", "msterile2")
|
||||
|
||||
|
@ -30,7 +30,7 @@ import inr.numass.actions.SummaryAction
|
||||
object NumassFitSummaryTask : AbstractTask<Table>(Table::class.java) {
|
||||
override val name: String = "summary"
|
||||
|
||||
override fun run(model: TaskModel, data: DataNode<*>): DataNode<out Table> {
|
||||
override fun run(model: TaskModel, data: DataNode<Any>): DataNode<Table> {
|
||||
val actionMeta = model.meta.getMeta("summary")
|
||||
val checkedData = data.getCheckedNode("fit", FitState::class.java)
|
||||
return SummaryAction.run(model.context, checkedData, actionMeta)
|
||||
|
@ -4,9 +4,6 @@ import hep.dataforge.data.CustomDataFilter
|
||||
import hep.dataforge.data.DataSet
|
||||
import hep.dataforge.data.DataTree
|
||||
import hep.dataforge.data.DataUtils
|
||||
import hep.dataforge.description.Description
|
||||
import hep.dataforge.description.ValueDef
|
||||
import hep.dataforge.description.ValueDefs
|
||||
import hep.dataforge.io.output.stream
|
||||
import hep.dataforge.io.render
|
||||
import hep.dataforge.kodex.nullable
|
||||
@ -44,9 +41,13 @@ import java.io.PrintWriter
|
||||
import java.util.*
|
||||
import java.util.concurrent.atomic.AtomicLong
|
||||
import java.util.stream.StreamSupport
|
||||
import kotlin.collections.set
|
||||
|
||||
|
||||
@Description("Select data from initial data pool")
|
||||
val selectTask = task("select") {
|
||||
descriptor {
|
||||
info = "Select data from initial data pool"
|
||||
}
|
||||
model { meta ->
|
||||
data("*")
|
||||
configure(meta.getMetaOrEmpty("data"))
|
||||
@ -59,8 +60,10 @@ val selectTask = task("select") {
|
||||
}
|
||||
}
|
||||
|
||||
@Description("Count the number of events for each voltage and produce a table with the results")
|
||||
val analyzeTask = task("analyze") {
|
||||
descriptor {
|
||||
info = "Count the number of events for each voltage and produce a table with the results"
|
||||
}
|
||||
model { meta ->
|
||||
dependsOn(selectTask, meta);
|
||||
configure(MetaUtils.optEither(meta, "analyzer", "prepare").orElse(Meta.empty()))
|
||||
@ -73,11 +76,11 @@ val analyzeTask = task("analyze") {
|
||||
}
|
||||
}
|
||||
|
||||
@ValueDefs(
|
||||
ValueDef(key = "showPlot", type = [ValueType.BOOLEAN], info = "Show plot after complete"),
|
||||
ValueDef(key = "monitorVoltage", type = [ValueType.NUMBER], info = "The voltage for monitor point")
|
||||
)
|
||||
val monitorTableTask = task("monitor") {
|
||||
descriptor {
|
||||
value("showPlot", types = listOf(ValueType.BOOLEAN), info = "Show plot after complete")
|
||||
value("monitorVoltage", types = listOf(ValueType.NUMBER), info = "The voltage for monitor point")
|
||||
}
|
||||
model { meta ->
|
||||
dependsOn(selectTask, meta)
|
||||
configure(meta.getMetaOrEmpty("monitor"))
|
||||
@ -99,7 +102,7 @@ val monitorTableTask = task("monitor") {
|
||||
).build()
|
||||
|
||||
if (meta.getBoolean("showPlot", true)) {
|
||||
val plot = DataPlot.plot(name, Adapters.buildXYAdapter("timestamp", "cr", "crErr"), res)
|
||||
val plot = DataPlot.plot(name, res, Adapters.buildXYAdapter("timestamp", "cr", "crErr"))
|
||||
context.plot(plot, "numass.monitor", name) {
|
||||
"xAxis.title" to "time"
|
||||
"xAxis.type" to "time"
|
||||
@ -259,7 +262,7 @@ val plotFitTask = task("plotFit") {
|
||||
StreamSupport.stream<Values>(data.spliterator(), false)
|
||||
.map { dp -> Adapters.getXValue(adapter, dp).double }.sorted().forEach { fit.calculateIn(it) }
|
||||
|
||||
val dataPlot = DataPlot.plot("data", adapter, data)
|
||||
val dataPlot = DataPlot.plot("data", data, adapter)
|
||||
|
||||
context.plot(listOf(fit, dataPlot), "numass.plotFit", name)
|
||||
|
||||
@ -267,10 +270,11 @@ val plotFitTask = task("plotFit") {
|
||||
}
|
||||
}
|
||||
|
||||
@Description("""
|
||||
Combine amplitude spectra from multiple sets, but with the same U.
|
||||
""")
|
||||
val histogramTask = task("histogram") {
|
||||
descriptor {
|
||||
value("plot",types = listOf(ValueType.BOOLEAN), defaultValue = false, info = "Show plot of the spectra")
|
||||
info = "Combine amplitude spectra from multiple sets, but with the same U"
|
||||
}
|
||||
model { meta ->
|
||||
dependsOn(selectTask, meta)
|
||||
configure(meta.getMetaOrEmpty("histogram"))
|
||||
@ -314,10 +318,19 @@ val histogramTask = task("histogram") {
|
||||
row(values)
|
||||
}
|
||||
}
|
||||
//TODO increase binning
|
||||
|
||||
context.output.render(table, stage = "numass.histogram", name = name, meta = meta)
|
||||
|
||||
//TODO add plot
|
||||
if (meta.getBoolean("plot", false)) {
|
||||
context.plot("$name.plot", stage = "numass.histogram") {
|
||||
plots.setType<DataPlot>()
|
||||
table.format.names.filter { it != "channel" }.forEach {
|
||||
+DataPlot.plot(it, table, adapter = Adapters.buildXYAdapter("channel", it))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return@join table
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ package inr.numass.models;
|
||||
|
||||
import hep.dataforge.stat.fit.ParamSet;
|
||||
import inr.numass.NumassPluginKt;
|
||||
import inr.numass.models.misc.LossCalculator;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -36,6 +37,6 @@ public class PlotScatter {
|
||||
+ "'ionW' = 11.33 ± 0.43\n"
|
||||
+ "'exIonRatio' = 4.83 ± 0.36"
|
||||
);
|
||||
LossCalculator.plotScatter(NumassPluginKt.displayChart("Loss function"), pars);
|
||||
LossCalculator.INSTANCE.plotScatter(NumassPluginKt.displayChart("Loss function"), pars);
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import hep.dataforge.maths.integration.GaussRuleIntegrator;
|
||||
import hep.dataforge.plots.PlotFrame;
|
||||
import hep.dataforge.plots.XYFunctionPlot;
|
||||
import inr.numass.NumassPluginKt;
|
||||
import inr.numass.models.misc.LossCalculator;
|
||||
import org.apache.commons.math3.analysis.UnivariateFunction;
|
||||
|
||||
/**
|
||||
@ -34,7 +35,7 @@ public class TestNeLossParametrisation {
|
||||
public static void main(String[] args) {
|
||||
PlotFrame frame = NumassPluginKt.displayChart("Loss parametrisation test");
|
||||
//JFreeChartFrame.drawFrame("Loss parametrisation test", null);
|
||||
UnivariateFunction oldFunction = LossCalculator.getSingleScatterFunction();
|
||||
UnivariateFunction oldFunction = LossCalculator.INSTANCE.getSingleScatterFunction();
|
||||
UnivariateFunction newFunction = getSingleScatterFunction(12.86, 16.78, 1.65, 12.38, 4.79);
|
||||
|
||||
Double norm = new GaussRuleIntegrator(200).integrate(0d, 100d, newFunction);
|
||||
|
@ -138,16 +138,16 @@ class AmplitudeView : View(title = "Numass amplitude spectrum plot", icon = Imag
|
||||
return@runGoal if (channels.size == 1) {
|
||||
DataPlot.plot(
|
||||
key,
|
||||
adapter,
|
||||
channels.values.first().withBinning(binning)
|
||||
channels.values.first().withBinning(binning),
|
||||
adapter
|
||||
)
|
||||
} else {
|
||||
val group = PlotGroup.typed<DataPlot>(key)
|
||||
channels.forEach { key, spectrum ->
|
||||
val plot = DataPlot.plot(
|
||||
key.toString(),
|
||||
adapter,
|
||||
spectrum.withBinning(binning)
|
||||
spectrum.withBinning(binning),
|
||||
adapter
|
||||
)
|
||||
group.add(plot)
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ class SlowControlView : View(title = "Numass slow control view", icon = ImageVie
|
||||
|
||||
names.forEach {
|
||||
val adapter = Adapters.buildXYAdapter("timestamp", it);
|
||||
val plot = DataPlot.plot(it, adapter, plotData).configure {
|
||||
val plot = DataPlot.plot(it, plotData, adapter).configure {
|
||||
"showLine" to true
|
||||
"showSymbol" to false
|
||||
"showErrors" to false
|
||||
|
Loading…
Reference in New Issue
Block a user