Fixed grid in JFreeChart

This commit is contained in:
Alexander Nozik 2018-07-27 15:34:46 +03:00
parent b02c14eb34
commit 2a83072d30
10 changed files with 69 additions and 72 deletions

View File

@ -19,12 +19,11 @@ package inr.numass.control.dante
import hep.dataforge.configure import hep.dataforge.configure
import hep.dataforge.context.Context import hep.dataforge.context.Context
import hep.dataforge.context.Global import hep.dataforge.context.Global
import hep.dataforge.fx.plots.displayPlot
import hep.dataforge.meta.KMetaBuilder import hep.dataforge.meta.KMetaBuilder
import hep.dataforge.meta.buildMeta import hep.dataforge.meta.buildMeta
import hep.dataforge.nullable import hep.dataforge.nullable
import hep.dataforge.plots.data.DataPlot import hep.dataforge.plots.data.DataPlot
import hep.dataforge.plots.jfreechart.chart import hep.dataforge.plots.output.plot
import hep.dataforge.tables.Adapters import hep.dataforge.tables.Adapters
import inr.numass.data.analyzers.NumassAnalyzer import inr.numass.data.analyzers.NumassAnalyzer
import inr.numass.data.analyzers.SimpleAnalyzer import inr.numass.data.analyzers.SimpleAnalyzer
@ -79,29 +78,27 @@ fun NumassBlock.plotAmplitudeSpectrum(plotName: String = "spectrum", frameName:
val lo = meta.optNumber("window.lo").nullable?.toInt() val lo = meta.optNumber("window.lo").nullable?.toInt()
val up = meta.optNumber("window.up").nullable?.toInt() val up = meta.optNumber("window.up").nullable?.toInt()
val data = SimpleAnalyzer().getAmplitudeSpectrum(this, meta.getMetaOrEmpty("spectrum")).withBinning(binning, lo, up) val data = SimpleAnalyzer().getAmplitudeSpectrum(this, meta.getMetaOrEmpty("spectrum")).withBinning(binning, lo, up)
context.displayPlot { context.plot(plotName) {
chart { val valueAxis = if (meta.getBoolean("normalize", false)) {
val valueAxis = if (meta.getBoolean("normalize", false)) { NumassAnalyzer.COUNT_RATE_KEY
NumassAnalyzer.COUNT_RATE_KEY } else {
} else { NumassAnalyzer.COUNT_KEY
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)
} }
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)
+plot
} }

View File

@ -1,5 +1,6 @@
package inr.numass.control package inr.numass.control
import hep.dataforge.configure
import hep.dataforge.fx.plots.PlotContainer import hep.dataforge.fx.plots.PlotContainer
import hep.dataforge.meta.KMetaBuilder import hep.dataforge.meta.KMetaBuilder
import hep.dataforge.plots.PlotFrame import hep.dataforge.plots.PlotFrame
@ -137,10 +138,8 @@ fun EventTarget.switch(text: String = "", op: (ToggleSwitch.() -> Unit) = {}): T
/** /**
* Add frame * Add frame
*/ */
fun BorderPane.plot(plottable: Plottable, metaTransform: (KMetaBuilder.() -> Unit)? = null): PlotFrame { fun BorderPane.plot(plottable: Plottable, metaTransform: (KMetaBuilder.() -> Unit) = {}): PlotFrame {
val meta = KMetaBuilder("plotFrame"); val frame = JFreeChartFrame().configure(metaTransform)
metaTransform?.invoke(meta)
val frame = JFreeChartFrame(meta)
frame.add(plottable) frame.add(plottable)
center = PlotContainer(frame).root center = PlotContainer(frame).root
return frame; return frame;

View File

@ -68,7 +68,7 @@ object PlotFitResultAction : OneToOneAction<FitResult, FitResult>() {
StreamSupport.stream(data.spliterator(), false) StreamSupport.stream(data.spliterator(), false)
.map { dp -> Adapters.getXValue(adapter, dp).double }.sorted().forEach{ fit.calculateIn(it) } .map { dp -> Adapters.getXValue(adapter, dp).double }.sorted().forEach{ fit.calculateIn(it) }
context.plot(listOf(fit,DataPlot.plot("data", data, adapter)), this.name, name) context.plot(listOf(fit,DataPlot.plot("data", data, adapter)), name, this.name)
return input return input
} }

View File

@ -77,7 +77,7 @@ object TimeAnalyzerAction : OneToOneAction<NumassPoint, Table>() {
cr / 1e6 * initialEstimate.getInt(NumassAnalyzer.COUNT_KEY) * binSize * Math.exp(-it * cr / 1e6) cr / 1e6 * initialEstimate.getInt(NumassAnalyzer.COUNT_KEY) * binSize * Math.exp(-it * cr / 1e6)
} }
context.plot(listOf(histogramPlot, functionPlot), stage = this.name, name = "histogram") { context.plot(listOf(histogramPlot, functionPlot), name = "histogram", stage = this.name) {
"xAxis" to { "xAxis" to {
"title" to "delay" "title" to "delay"
"units" to "us" "units" to "us"
@ -105,7 +105,7 @@ object TimeAnalyzerAction : OneToOneAction<NumassPoint, Table>() {
"title" to "${name}_${input.voltage}" "title" to "${name}_${input.voltage}"
} }
context.plot(statPlot, stage = this.name, name = "count rate") { context.plot(statPlot, name = "count rate", stage = this.name) {
"xAxis" to { "xAxis" to {
"title" to "delay" "title" to "delay"
"units" to "us" "units" to "us"
@ -115,7 +115,7 @@ object TimeAnalyzerAction : OneToOneAction<NumassPoint, Table>() {
} }
} }
context.plot(errorPlot, stage = this.name, name = "error"){ context.plot(errorPlot, name = "error", stage = this.name){
"xAxis" to { "xAxis" to {
"title" to "delay" "title" to "delay"
"units" to "us" "units" to "us"

View File

@ -82,7 +82,7 @@ object TimeSpectrumAction : OneToOneAction<NumassPoint, Table>() {
.fillData(histogram) .fillData(histogram)
context.plot(histogramPlot, "histogram", name) { context.plot(histogramPlot, name, "histogram") {
"xAxis" to { "xAxis" to {
"title" to "delay" "title" to "delay"
"units" to "us" "units" to "us"
@ -103,7 +103,7 @@ object TimeSpectrumAction : OneToOneAction<NumassPoint, Table>() {
configure(inputMeta.getMetaOrEmpty("plot")) configure(inputMeta.getMetaOrEmpty("plot"))
} }
context.plot(statPlot, "stat-method", name) context.plot(statPlot, name, "stat-method")
(1..100).map { 1000 * it }.map { t -> (1..100).map { 1000 * it }.map { t ->
val result = analyzer.analyze(input, buildMeta { val result = analyzer.analyze(input, buildMeta {

View File

@ -16,15 +16,13 @@
package inr.numass.data package inr.numass.data
import hep.dataforge.configure
import hep.dataforge.context.Context import hep.dataforge.context.Context
import hep.dataforge.context.Global import hep.dataforge.context.Global
import hep.dataforge.fx.plots.displayPlot
import hep.dataforge.meta.KMetaBuilder import hep.dataforge.meta.KMetaBuilder
import hep.dataforge.meta.buildMeta import hep.dataforge.meta.buildMeta
import hep.dataforge.nullable import hep.dataforge.nullable
import hep.dataforge.plots.data.DataPlot import hep.dataforge.plots.data.DataPlot
import hep.dataforge.plots.jfreechart.chart import hep.dataforge.plots.output.plot
import hep.dataforge.tables.Adapters import hep.dataforge.tables.Adapters
import inr.numass.data.analyzers.NumassAnalyzer import inr.numass.data.analyzers.NumassAnalyzer
import inr.numass.data.analyzers.SmartAnalyzer import inr.numass.data.analyzers.SmartAnalyzer
@ -38,28 +36,26 @@ fun NumassBlock.plotAmplitudeSpectrum(plotName: String = "spectrum", frameName:
val lo = meta.optNumber("window.lo").nullable?.toInt() val lo = meta.optNumber("window.lo").nullable?.toInt()
val up = meta.optNumber("window.up").nullable?.toInt() val up = meta.optNumber("window.up").nullable?.toInt()
val data = SmartAnalyzer().getAmplitudeSpectrum(this, meta.getMetaOrEmpty("spectrum")).withBinning(binning, lo, up) val data = SmartAnalyzer().getAmplitudeSpectrum(this, meta.getMetaOrEmpty("spectrum")).withBinning(binning, lo, up)
context.displayPlot { context.plot(plotName) {
chart { val valueAxis = if (meta.getBoolean("normalize", false)) {
val valueAxis = if (meta.getBoolean("normalize", false)) { NumassAnalyzer.COUNT_RATE_KEY
NumassAnalyzer.COUNT_RATE_KEY } else {
} else { NumassAnalyzer.COUNT_KEY
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)
} }
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)
} }
} }

View File

@ -1,11 +1,10 @@
package inr.numass.models.mc package inr.numass.models.mc
import hep.dataforge.context.Global import hep.dataforge.context.Global
import hep.dataforge.fx.plots.displayPlot
import hep.dataforge.maths.chain.Chain import hep.dataforge.maths.chain.Chain
import hep.dataforge.meta.buildMeta import hep.dataforge.meta.buildMeta
import hep.dataforge.plots.data.XYFunctionPlot import hep.dataforge.plots.data.XYFunctionPlot
import hep.dataforge.plots.jfreechart.chart import hep.dataforge.plots.output.plot
import hep.dataforge.stat.PolynomialDistribution import hep.dataforge.stat.PolynomialDistribution
import hep.dataforge.stat.fit.ParamSet import hep.dataforge.stat.fit.ParamSet
import inr.numass.NumassPlugin import inr.numass.NumassPlugin
@ -47,10 +46,8 @@ fun main(args: Array<String>) {
50 * distribution.density(18600.0 - it) 50 * distribution.density(18600.0 - it)
} }
Global.displayPlot { Global.plot("beta") {
chart { add(spectrumPlot)
add(spectrumPlot) add(distributionPlot)
add(distributionPlot)
}
} }
} }

View File

@ -30,7 +30,10 @@ fun main(args: Array<String>) {
val point = (1..num).map { val point = (1..num).map {
Global.generate { Global.generate {
NumassGenerator.generateEvents(cr).withDeadTime { (dt * 1000).toLong() }.generateBlock(start.plusNanos(it * length), length) NumassGenerator
.generateEvents(cr)
.withDeadTime { (dt * 1000).toLong() }
.generateBlock(start.plusNanos(it * length), length)
} }
}.join(Global.coroutineContext) { blocks -> }.join(Global.coroutineContext) { blocks ->
SimpleNumassPoint(blocks, 12000.0) SimpleNumassPoint(blocks, 12000.0)
@ -44,8 +47,10 @@ fun main(args: Array<String>) {
"mean" to TimeAnalyzer.AveragingMethod.ARITHMETIC "mean" to TimeAnalyzer.AveragingMethod.ARITHMETIC
} }
"binNum" to 200 "binNum" to 200
"t0.max" to 1e4 "t0.max" to 5e4
} }
TimeAnalyzerAction.simpleRun(point, meta); TimeAnalyzerAction.simpleRun(point, meta);
readLine()
} }

View File

@ -49,12 +49,15 @@ fun main(args: Array<String>) {
.generateEvents(cr) .generateEvents(cr)
val bunches = NumassGenerator val bunches = NumassGenerator
.generateBunches(10.0, 0.001, 5.0) .generateBunches(3.0, 0.001, 5.0)
val discharges = NumassGenerator val discharges = NumassGenerator
.generateBunches(50.0,0.001,0.1) .generateBunches(50.0,0.001,0.1)
NumassGenerator.mergeEventChains(events, bunches, discharges).withDeadTime { (dt * 1000).toLong() }.generateBlock(start.plusNanos(it * length), length) NumassGenerator
.mergeEventChains(events, bunches, discharges)
.withDeadTime { (dt * 1000).toLong() }
.generateBlock(start.plusNanos(it * length), length)
} }
}.join(Global.coroutineContext) { blocks -> }.join(Global.coroutineContext) { blocks ->
SimpleNumassPoint(blocks, 18000.0) SimpleNumassPoint(blocks, 18000.0)

View File

@ -107,7 +107,7 @@ val monitorTableTask = task("monitor") {
if (meta.getBoolean("showPlot", true)) { if (meta.getBoolean("showPlot", true)) {
val plot = DataPlot.plot(name, res, Adapters.buildXYAdapter("timestamp", "cr", "crErr")) val plot = DataPlot.plot(name, res, Adapters.buildXYAdapter("timestamp", "cr", "crErr"))
context.plot(plot, "numass.monitor", name) { context.plot(plot, name, "numass.monitor") {
"xAxis.title" to "time" "xAxis.title" to "time"
"xAxis.type" to "time" "xAxis.type" to "time"
"yAxis.title" to "Count rate" "yAxis.title" to "Count rate"
@ -268,7 +268,7 @@ val plotFitTask = task("plotFit") {
val dataPlot = DataPlot.plot("data", data, adapter) val dataPlot = DataPlot.plot("data", data, adapter)
context.plot(listOf(fit, dataPlot), "numass.plotFit", name) context.plot(listOf(fit, dataPlot), name, "numass.plotFit")
return@pipe input; return@pipe input;
} }