Some fixes

This commit is contained in:
Alexander Nozik 2018-10-30 17:26:57 +03:00
parent edef7762f3
commit 15e7974225
6 changed files with 104 additions and 10 deletions

View File

@ -58,7 +58,6 @@ class NumassPlugin : BasicPlugin() {
}
private val tasks = listOf(
NumassFitScanTask,
NumassFitScanSummaryTask,
NumassFitSummaryTask,
selectTask,
@ -71,7 +70,8 @@ class NumassPlugin : BasicPlugin() {
filterTask,
fitTask,
plotFitTask,
histogramTask
histogramTask,
fitScanTask
)
@Provides(Task.TASK_TARGET)
@ -220,6 +220,13 @@ class NumassPlugin : BasicPlugin() {
}
library.addModel("sterile") { context, meta ->
val sp = SterileNeutrinoSpectrum(context, meta)
val spectrum = NBkgSpectrum(sp)
XYModel(meta, getAdapter(meta), spectrum)
}
library.addModel("sterile-corrected") { context, meta ->
val sp = SterileNeutrinoSpectrum(context, meta)
val spectrum = NBkgSpectrumWithCorrection(sp)

View File

@ -0,0 +1,20 @@
package inr.numass.scripts.analysis
import hep.dataforge.context.Global
import hep.dataforge.fx.output.FXOutputManager
import hep.dataforge.workspace.FileBasedWorkspace
import java.io.File
fun main(args: Array<String>) {
FXOutputManager().startGlobal()
val configPath = File("D:\\Work\\Numass\\sterile2017_05\\workspace.groovy").toPath()
val workspace = FileBasedWorkspace.build(Global, configPath)
workspace.context.setValue("cache.enabled", false)
//val meta = workspace.getTarget("group_3")
val result = workspace.runTask("scansum", "group_3").first().get()
println("Complete!")
}

View File

@ -1,6 +1,7 @@
package inr.numass.scripts.analysis
import hep.dataforge.context.Global
import hep.dataforge.fx.output.FXOutputManager
import hep.dataforge.plots.plotData
import hep.dataforge.tables.Adapters
import hep.dataforge.tables.Table
@ -19,6 +20,8 @@ fun main(args: Array<String>) {
// }
// }
FXOutputManager().startGlobal()
val configPath = File("D:\\Work\\Numass\\sterile2017_11\\workspace.groovy").toPath()

View File

@ -20,6 +20,7 @@ import hep.dataforge.buildContext
import hep.dataforge.fx.output.FXOutputManager
import hep.dataforge.io.DirectoryOutput
import hep.dataforge.io.plus
import hep.dataforge.io.render
import hep.dataforge.meta.buildMeta
import hep.dataforge.nullable
import hep.dataforge.plots.data.DataPlot
@ -27,6 +28,8 @@ import hep.dataforge.plots.jfreechart.JFreeChartPlugin
import hep.dataforge.plots.plotData
import hep.dataforge.storage.files.FileStorage
import hep.dataforge.tables.Adapters
import hep.dataforge.tables.filter
import hep.dataforge.tables.sort
import inr.numass.NumassPlugin
import inr.numass.data.NumassDataUtils
import inr.numass.data.api.NumassSet
@ -36,8 +39,8 @@ 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_11"
dataDir = "D:\\Work\\Numass\\data\\2017_11"
rootDir = "D:\\Work\\Numass\\sterile\\2017_05"
dataDir = "D:\\Work\\Numass\\data\\2017_05"
output = FXOutputManager() + DirectoryOutput()
}
@ -59,18 +62,21 @@ fun main(args: Array<String>) {
plots.setType<DataPlot>()
}
val sets = (36..42).map { "set_$it" }.map { setName ->
storage.provide(setName, NumassSet::class.java).nullable ?: error("Set does not exist")
}
val name = "fill_2[36-42]"
val sets = (1..18).map { "set_$it" }.map { setName ->
storage.provide(setName, NumassSet::class.java).nullable
}.filterNotNull()
val name = "fill_2[1-18]"
val sum = NumassDataUtils.join(name, sets)
val correctionTable = Threshold.calculateSubThreshold(sum, meta).filter {
it.getDouble("correction") in (1.0..1.2)
}
}.sort("voltage")
frame.plotData("${name}_cor", correctionTable, Adapters.buildXYAdapter("U", "correction"))
frame.plotData("${name}_a", correctionTable, Adapters.buildXYAdapter("U", "a"))
frame.plotData("${name}_beta", correctionTable, Adapters.buildXYAdapter("U", "beta"))
context.output.render(correctionTable,"numass.correction", "fill_2[1-18]")
}

View File

@ -43,7 +43,7 @@ object NumassFitScanSummaryTask : AbstractTask<Table>(Table::class.java) {
override val name = "scansum"
@TypedActionDef(name = "sterileSummary", inputType = FitResult::class, outputType = Table::class)
private class FitSummaryAction : ManyToOneAction<FitResult, Table>("sterileSummary",FitResult::class.java,Table::class.java) {
private class FitSummaryAction : ManyToOneAction<FitResult, Table>("sterileSummary", FitResult::class.java,Table::class.java) {
override fun execute(context: Context, nodeName: String, input: Map<String, FitResult>, meta: Laminate): Table {
val builder = ListTable.Builder("m", "U2", "U2err", "U2limit", "E0", "trap")

View File

@ -24,6 +24,7 @@ import hep.dataforge.tables.*
import hep.dataforge.useMeta
import hep.dataforge.values.ValueType
import hep.dataforge.values.Values
import hep.dataforge.values.asValue
import hep.dataforge.workspace.tasks.task
import inr.numass.NumassUtils
import inr.numass.actions.MergeDataAction
@ -366,3 +367,60 @@ val histogramTask = task("histogram") {
return@join table
}
}
val fitScanTask = task("fitscan") {
model { meta ->
dependsOn(filterTask, meta)
configure{
setNode(meta.getMetaOrEmpty("scan"))
setNode(meta.getMeta("fit"))
}
}
splitAction<Table, FitResult> {
val scanMeta = meta.getMeta("scan")
val scanValues = if (scanMeta.hasValue("masses")) {
scanMeta.getValue("masses").list.map { it -> Math.pow(it.double * 1000, 2.0).asValue() }
} else {
scanMeta.getValue("values", listOf(2.5e5, 1e6, 2.25e6, 4e6, 6.25e6, 9e6)).list
}
val scanParameter = scanMeta.getString("parameter", "msterile2")
scanValues.forEach { scanValue ->
val resultName = String.format("%s[%s=%s]", this.name, scanParameter, scanValue.string)
val fitMeta = meta.getMeta("fit").builder.apply {
setValue("@nameSuffix", String.format("[%s=%s]", scanParameter, scanValue.string))
if (hasMeta("params.$scanParameter")) {
setValue("params.$scanParameter.value", scanValue)
} else {
getMetaList("params.param").stream()
.filter { par -> par.getString("name") == scanParameter }
.forEach { it.setValue("value", it) }
}
}
fragment(resultName) {
result { data ->
context.output["numass.fitscan", name].stream.use { out ->
val writer = PrintWriter(out)
writer.printf("%n*** META ***%n")
writer.println(fitMeta.toString())
writer.flush()
FitHelper(context).fit(data, fitMeta)
.setListenerStream(out)
.report(log)
.run()
.also {
if (fitMeta.getBoolean("printLog", true)) {
writer.println()
log.entries.forEach { entry -> writer.println(entry.toString()) }
writer.println()
}
}
}
}
}
}
}
}