Minor fixes in plots

This commit is contained in:
Alexander Nozik 2018-06-27 22:12:23 +03:00
parent a11f8d99d0
commit 34eb8fc559
3 changed files with 107 additions and 29 deletions

View File

@ -38,7 +38,7 @@ 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.display( context.display {
JFreeChartFrame().apply { JFreeChartFrame().apply {
val valueAxis = if (meta.getBoolean("normalize", false)) { val valueAxis = if (meta.getBoolean("normalize", false)) {
NumassAnalyzer.COUNT_RATE_KEY NumassAnalyzer.COUNT_RATE_KEY
@ -61,5 +61,5 @@ fun NumassBlock.plotAmplitudeSpectrum(plotName: String = "spectrum", frameName:
plot.configure(meta) plot.configure(meta)
add(plot) add(plot)
} }
) }
} }

View File

@ -47,10 +47,10 @@ fun main(args: Array<String>) {
50 * distribution.density(18600.0 - it) 50 * distribution.density(18600.0 - it)
} }
Global.display( Global.display {
chart { chart {
add(spectrumPlot) add(spectrumPlot)
add(distributionPlot) add(distributionPlot)
} }
) }
} }

View File

@ -0,0 +1,78 @@
/*
* 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.models
import hep.dataforge.context.Global
import hep.dataforge.fx.plots.display
import hep.dataforge.kodex.configure
import hep.dataforge.kodex.step
import hep.dataforge.meta.Meta
import hep.dataforge.plots.Plot
import hep.dataforge.plots.data.DataPlot
import hep.dataforge.plots.jfreechart.JFreeChartFrame
import hep.dataforge.plots.jfreechart.JFreeChartPlugin
import hep.dataforge.stat.fit.ParamSet
import inr.numass.NumassPlugin
import inr.numass.models.NBkgSpectrum
import inr.numass.models.sterile.SterileNeutrinoSpectrum
fun main(args: Array<String>) {
JFreeChartPlugin().startGlobal()
NumassPlugin().startGlobal()
val sp = SterileNeutrinoSpectrum(Global, Meta.empty())
//beta.setCaching(false);
val spectrum = NBkgSpectrum(sp)
//val model = XYModel(Meta.empty(), SpectrumAdapter(Meta.empty()), spectrum)
val params = ParamSet().apply {
setPar("N", 2e6 / 100, 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", (8000 * 8000).toDouble())
setPar("U2", 0.0, 1e-3)
setPar("X", 0.1, 0.01)
setPar("trap", 1.0, 0.01)
}
fun plotSpectrum(name: String, vararg override: Pair<String, Double>): Plot {
val pars = params.copy().apply {
override.forEach {
setParValue(it.first,it.second)
}
}
val x = (14000.0..18600.0).step(100.0).toList()
val y = x.map { spectrum.value(it, pars) }
return DataPlot.plot(name, x.toDoubleArray(), y.toDoubleArray())
}
Global.display {
JFreeChartFrame().apply {
plots.configure {
"showLine" to true
"showSymbol" to false
"showErrors" to false
}
add(plotSpectrum("base"))
add(plotSpectrum("noTrap", "trap" to 0.0))
}
}
}