Numass tasks update

This commit is contained in:
Alexander Nozik 2017-10-23 13:11:26 +03:00
parent 6b8faf4eb7
commit 44ebe4680a
14 changed files with 382 additions and 445 deletions

View File

@ -42,8 +42,7 @@ public class MergeDataAction extends ManyToOneAction<Table, Table> {
public static String[] parnames = {NumassPoint.HV_KEY, NumassPoint.LENGTH_KEY, NumassAnalyzer.COUNT_KEY, NumassAnalyzer.COUNT_RATE_KEY, NumassAnalyzer.COUNT_RATE_ERROR_KEY}; public static String[] parnames = {NumassPoint.HV_KEY, NumassPoint.LENGTH_KEY, NumassAnalyzer.COUNT_KEY, NumassAnalyzer.COUNT_RATE_KEY, NumassAnalyzer.COUNT_RATE_ERROR_KEY};
@Override @Override
@SuppressWarnings("unchecked") protected List<DataNode<Table>> buildGroups(Context context, DataNode<Table> input, Meta actionMeta) {
protected List<DataNode<Table>> buildGroups(Context context, DataNode input, Meta actionMeta) {
Meta meta = inputMeta(context, input.meta(), actionMeta); Meta meta = inputMeta(context, input.meta(), actionMeta);
List<DataNode<Table>> groups; List<DataNode<Table>> groups;
if (meta.hasValue("grouping.byValue")) { if (meta.hasValue("grouping.byValue")) {

View File

@ -1,88 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package inr.numass.tasks;
import hep.dataforge.actions.Action;
import hep.dataforge.actions.ManyToOneAction;
import hep.dataforge.context.Context;
import hep.dataforge.data.DataNode;
import hep.dataforge.data.DataSet;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.meta.Laminate;
import hep.dataforge.meta.Meta;
import hep.dataforge.stat.fit.FitResult;
import hep.dataforge.stat.fit.ParamSet;
import hep.dataforge.stat.fit.UpperLimitGenerator;
import hep.dataforge.tables.ListTable;
import hep.dataforge.tables.Table;
import hep.dataforge.tables.TableTransform;
import hep.dataforge.workspace.tasks.AbstractTask;
import hep.dataforge.workspace.tasks.TaskModel;
import inr.numass.NumassUtils;
import java.util.Map;
/**
* @author Alexander Nozik
*/
public class NumassFitScanSummaryTask extends AbstractTask<Table> {
@Override
protected DataNode<Table> run(TaskModel model, DataNode<?> data) {
DataSet.Builder<Table> builder = DataSet.builder(Table.class);
Action<FitResult, Table> action = new FitSummaryAction();
DataNode<FitResult> input = data.getCheckedNode("fitscan", FitResult.class);
input.nodeStream().filter(it -> it.dataSize(false) > 0).forEach(node ->
builder.putData(node.getName(), action.run(model.getContext(), node, model.meta()).getData())
);
return builder.build();
}
@Override
protected void buildModel(TaskModel.Builder model, Meta meta) {
model.dependsOn("fitscan", meta, "fitscan");
}
@Override
public String getName() {
return "scansum";
}
@TypedActionDef(name = "sterileSummary", inputType = FitResult.class, outputType = Table.class)
private class FitSummaryAction extends ManyToOneAction<FitResult, Table> {
@Override
protected Table execute(Context context, String nodeName, Map<String, FitResult> input, Laminate meta) {
ListTable.Builder builder = new ListTable.Builder("m", "U2", "U2err", "U2limit", "E0", "trap");
input.forEach((key, fitRes) -> {
ParamSet pars = fitRes.getParameters();
double u2Val = pars.getDouble("U2") / pars.getError("U2");
double limit;
if (Math.abs(u2Val) < 3) {
limit = UpperLimitGenerator.getConfidenceLimit(u2Val) * pars.getError("U2");
} else {
limit = Double.NaN;
}
builder.row(
Math.sqrt(pars.getValue("msterile2").doubleValue()),
pars.getValue("U2"),
pars.getError("U2"),
limit,
pars.getValue("E0"),
pars.getValue("trap"));
});
Table res = TableTransform.sort(builder.build(), "m", true);
output(context, nodeName, stream -> NumassUtils.INSTANCE.write(stream,meta,res));
return res;
}
}
}

View File

@ -1,98 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package inr.numass.tasks;
import hep.dataforge.actions.Action;
import hep.dataforge.data.DataNode;
import hep.dataforge.data.DataTree;
import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.stat.fit.FitAction;
import hep.dataforge.stat.fit.FitResult;
import hep.dataforge.tables.Table;
import hep.dataforge.values.Value;
import hep.dataforge.workspace.tasks.AbstractTask;
import hep.dataforge.workspace.tasks.TaskModel;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* @author Alexander Nozik
*/
public class NumassFitScanTask extends AbstractTask<FitResult> {
@Override
protected DataNode<FitResult> run(TaskModel model, DataNode<?> data) {
Meta config = model.meta();
String scanParameter = config.getString("parameter", "msterile2");
Value scanValues;
if (config.hasValue("masses")) {
scanValues = Value.of(config.getValue("masses")
.listValue().stream()
.map(it -> Math.pow(it.doubleValue() * 1000, 2.0))
.collect(Collectors.toList())
);
} else {
scanValues = config.getValue("values", Value.of("[2.5e5, 1e6, 2.25e6, 4e6, 6.25e6, 9e6]"));
}
Action<Table, FitResult> action = new FitAction();
DataTree.Builder<FitResult> resultBuilder = DataTree.builder(FitResult.class);
DataNode<Table> sourceNode = data.getCheckedNode("prepare", Table.class);
if (config.hasMeta("merge")) {
//use merged data and ignore raw data
sourceNode = sourceNode.getCheckedNode("merge", Table.class);
}
//do fit
Meta fitConfig = config.getMeta("fit");
sourceNode.dataStream().forEach(table -> {
for (int i = 0; i < scanValues.listValue().size(); i++) {
Value val = scanValues.listValue().get(i);
MetaBuilder overrideMeta = new MetaBuilder(fitConfig);
String resultName = String.format("%s[%s=%s]", table.getName(), scanParameter, val.stringValue());
// overrideMeta.setValue("@resultName", String.format("%s[%s=%s]", table.getName(), scanParameter, val.stringValue()));
if (overrideMeta.hasMeta("params." + scanParameter)) {
overrideMeta.setValue("params." + scanParameter + ".value", val);
} else {
overrideMeta.getMetaList("params.param").stream()
.filter(par -> Objects.equals(par.getString("name"), scanParameter)).forEach(par -> par.setValue("value", val));
}
// Data<Table> newData = new Data<Table>(data.getGoal(),data.type(),overrideMeta);
DataNode<FitResult> node = action.run(model.getContext(), DataNode.of(resultName, table, Meta.empty()), overrideMeta);
resultBuilder.putData(table.getName() + ".fit_" + i, node.getData());
}
});
return resultBuilder.build();
}
@Override
protected void buildModel(TaskModel.Builder model, Meta meta) {
model.configure(meta.getMetaOrEmpty("scan"));
model.configure(it->it.putNode(meta.getMetaOrEmpty("fit")));
if (meta.hasMeta("filter")) {
model.dependsOn("filter", meta, "prepare");
} else if (meta.hasMeta("empty")) {
model.dependsOn("subtractEmpty", meta, "prepare");
} else {
model.dependsOn("prepare", meta, "prepare");
}
}
@Override
public String getName() {
return "fitscan";
}
}

View File

@ -1,56 +0,0 @@
/*
* Copyright 2015 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.tasks;
import hep.dataforge.actions.Action;
import hep.dataforge.data.DataNode;
import hep.dataforge.meta.Meta;
import hep.dataforge.stat.fit.FitState;
import hep.dataforge.tables.Table;
import hep.dataforge.workspace.tasks.SingleActionTask;
import hep.dataforge.workspace.tasks.TaskModel;
import inr.numass.actions.SummaryAction;
/**
* Created by darksnake on 16-Sep-16.
*/
public class NumassFitSummaryTask extends SingleActionTask<FitState, Table> {
@Override
public String getName() {
return "summary";
}
@Override
protected Action<FitState, Table> getAction(TaskModel model) {
return new SummaryAction();
}
@Override
protected DataNode<FitState> gatherNode(DataNode<?> data) {
return data.getCheckedNode("fit", FitState.class);
}
@Override
protected Meta transformMeta(TaskModel model) {
return model.meta().getMeta("summary");
}
@Override
protected void buildModel(TaskModel.Builder model, Meta meta) {
model.dependsOn("fit", meta, "fit");
}
}

View File

@ -1,78 +0,0 @@
/*
* Copyright 2015 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.tasks;
import hep.dataforge.actions.Action;
import hep.dataforge.actions.ActionUtils;
import hep.dataforge.data.DataNode;
import hep.dataforge.meta.Meta;
import hep.dataforge.plotfit.PlotFitResultAction;
import hep.dataforge.stat.fit.FitAction;
import hep.dataforge.stat.fit.FitResult;
import hep.dataforge.tables.Table;
import hep.dataforge.workspace.tasks.SingleActionTask;
import hep.dataforge.workspace.tasks.TaskModel;
/**
* Created by darksnake on 16-Sep-16.
*/
public class NumassFitTask extends SingleActionTask<Table, FitResult> {
@Override
public String getName() {
return "fit";
}
@Override
protected DataNode<Table> gatherNode(DataNode<?> data) {
return data.getCheckedNode("prepare", Table.class);
}
@Override
public void validate(TaskModel model) {
if (model.meta().isEmpty()) {
throw new RuntimeException("Fit element not found in model");
}
}
@Override
protected Action<Table, FitResult> getAction(TaskModel model) {
Action<Table, FitResult> action = new FitAction();
if (model.meta().getBoolean("frame", false)) {
return ActionUtils.compose(action, new PlotFitResultAction());
} else {
return action;
}
}
@Override
protected Meta transformMeta(TaskModel model) {
return model.meta();
}
@Override
protected void buildModel(TaskModel.Builder model, Meta meta) {
if (meta.hasMeta("filter")) {
model.dependsOn("filter", meta, "prepare");
} else if (meta.hasMeta("empty")) {
model.dependsOn("subtractEmpty", meta, "prepare");
} else {
model.dependsOn("prepare", meta, "prepare");
}
}
}

View File

@ -31,6 +31,7 @@ import inr.numass.data.api.NumassSet;
@NodeDef(name = "prepare") @NodeDef(name = "prepare")
@NodeDef(name = "monitor") @NodeDef(name = "monitor")
@NodeDef(name = "merge") @NodeDef(name = "merge")
@Deprecated
public class NumassPrepareTask extends AbstractTask<Table> { public class NumassPrepareTask extends AbstractTask<Table> {
@Override @Override

View File

@ -1,98 +0,0 @@
package inr.numass.tasks;
import hep.dataforge.actions.Action;
import hep.dataforge.actions.OneToOneAction;
import hep.dataforge.context.Context;
import hep.dataforge.data.DataNode;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.meta.Laminate;
import hep.dataforge.meta.Meta;
import hep.dataforge.tables.Table;
import hep.dataforge.tables.TableTransform;
import hep.dataforge.values.Value;
import hep.dataforge.values.Values;
import hep.dataforge.workspace.tasks.SingleActionTask;
import hep.dataforge.workspace.tasks.TaskModel;
import inr.numass.utils.ExpressionUtils;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Predicate;
/**
* Created by darksnake on 13-Aug-16.
*/
public class NumassTableFilterTask extends SingleActionTask<Table, Table> {
@Override
public String getName() {
return "filter";
}
@Override
protected DataNode<Table> gatherNode(DataNode<?> data) {
return data.getCheckedNode("prepare", Table.class);
}
@Override
protected void buildModel(TaskModel.Builder model, Meta meta) {
if (meta.hasMeta("empty")) {
model.dependsOn("subtractEmpty", meta, "prepare");
} else {
model.dependsOn("prepare", meta, "prepare");
}
}
@Override
protected Action<Table, Table> getAction(TaskModel model) {
return new FilterTableAction();
}
@TypedActionDef(name = "filterTable", inputType = Table.class, outputType = Table.class)
private class FilterTableAction extends OneToOneAction<Table, Table> {
@Override
protected Table execute(Context context, String name, Table input, Laminate inputMeta) {
if (inputMeta.hasValue("from") || inputMeta.hasValue("to")) {
double uLo = inputMeta.getDouble("from", 0);
double uHi = inputMeta.getDouble("to", Double.POSITIVE_INFINITY);
getLogger(context,inputMeta).debug("Filtering finished");
return TableTransform.filter(input, "Uset", uLo, uHi);
} else if (inputMeta.hasValue("condition")) {
Predicate<Values> predicate = (dp) -> ExpressionUtils.condition(inputMeta.getString("condition"), unbox(dp));
return TableTransform.filter(input, predicate);
} else {
throw new RuntimeException("No filtering condition specified");
}
}
}
private Map<String, Object> unbox(Values dp) {
Map<String, Object> res = new HashMap<>();
for (String field : dp.getNames()) {
Value val = dp.getValue(field);
Object obj;
switch (val.getType()) {
case BOOLEAN:
obj = val.booleanValue();
break;
case NUMBER:
obj = val.doubleValue();
break;
case STRING:
obj = val.stringValue();
break;
case TIME:
obj = val.timeValue();
break;
case NULL:
obj = null;
break;
default:
throw new Error("unreachable statement");
}
res.put(field, obj);
}
return res;
}
}

View File

@ -22,8 +22,6 @@ import hep.dataforge.context.PluginDef
import hep.dataforge.kodex.fx.plots.PlotContainer import hep.dataforge.kodex.fx.plots.PlotContainer
import hep.dataforge.maths.MathPlugin import hep.dataforge.maths.MathPlugin
import hep.dataforge.meta.Meta import hep.dataforge.meta.Meta
import hep.dataforge.plotfit.PlotFitResultAction
import hep.dataforge.plots.PlotDataAction
import hep.dataforge.plots.jfreechart.JFreeChartFrame import hep.dataforge.plots.jfreechart.JFreeChartFrame
import hep.dataforge.stat.fit.FitManager import hep.dataforge.stat.fit.FitManager
import hep.dataforge.stat.models.ModelManager import hep.dataforge.stat.models.ModelManager
@ -31,7 +29,6 @@ import hep.dataforge.stat.models.WeightedXYModel
import hep.dataforge.stat.models.XYModel import hep.dataforge.stat.models.XYModel
import hep.dataforge.tables.ValuesAdapter import hep.dataforge.tables.ValuesAdapter
import hep.dataforge.tables.XYAdapter import hep.dataforge.tables.XYAdapter
import inr.numass.actions.*
import inr.numass.data.api.NumassAnalyzer import inr.numass.data.api.NumassAnalyzer
import inr.numass.data.api.NumassPoint import inr.numass.data.api.NumassPoint
import inr.numass.models.* import inr.numass.models.*
@ -64,15 +61,6 @@ class NumassPlugin : BasicPlugin() {
val actions = context.pluginManager().getOrLoad(ActionManager::class.java) val actions = context.pluginManager().getOrLoad(ActionManager::class.java)
actions.attach(context) actions.attach(context)
actions.putAction(MergeDataAction::class.java)
actions.putAction(MonitorCorrectAction::class.java)
actions.putAction(SummaryAction::class.java)
actions.putAction(PlotDataAction::class.java)
actions.putAction(PlotFitResultAction::class.java)
actions.putAction(AdjustErrorsAction::class.java)
actions.putAction(SubstractSpectrumAction::class.java)
//actions.putTask(NumassPrepareTask::class.java)
actions.putTask(NumassTableFilterTask::class.java) actions.putTask(NumassTableFilterTask::class.java)
actions.putTask(NumassFitScanTask::class.java) actions.putTask(NumassFitScanTask::class.java)
actions.putTask(NumassFitScanSummaryTask::class.java) actions.putTask(NumassFitScanSummaryTask::class.java)
@ -84,11 +72,7 @@ class NumassPlugin : BasicPlugin() {
actions.put(mergeEmptyTask) actions.put(mergeEmptyTask)
actions.put(monitorTableTask) actions.put(monitorTableTask)
actions.put(subtractEmptyTask) actions.put(subtractEmptyTask)
} actions.put(transformTask)
override fun detach() {
//TODO clean up
super.detach()
} }
private fun loadMath(math: MathPlugin) { private fun loadMath(math: MathPlugin) {

View File

@ -0,0 +1,78 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package inr.numass.tasks
import hep.dataforge.actions.ManyToOneAction
import hep.dataforge.context.Context
import hep.dataforge.data.DataNode
import hep.dataforge.data.DataSet
import hep.dataforge.description.TypedActionDef
import hep.dataforge.meta.Laminate
import hep.dataforge.meta.Meta
import hep.dataforge.stat.fit.FitResult
import hep.dataforge.stat.fit.UpperLimitGenerator
import hep.dataforge.tables.ListTable
import hep.dataforge.tables.Table
import hep.dataforge.tables.TableTransform
import hep.dataforge.workspace.tasks.AbstractTask
import hep.dataforge.workspace.tasks.TaskModel
import inr.numass.NumassUtils
/**
* @author Alexander Nozik
*/
class NumassFitScanSummaryTask : AbstractTask<Table>() {
override fun run(model: TaskModel, data: DataNode<*>): DataNode<Table> {
val builder = DataSet.builder(Table::class.java)
val action = FitSummaryAction()
val input = data.getCheckedNode("fitscan", FitResult::class.java)
input.nodeStream().filter { it -> it.dataSize(false) > 0 }.forEach { node -> builder.putData(node.name, action.run(model.context, node, model.meta()).data) }
return builder.build()
}
override fun buildModel(model: TaskModel.Builder, meta: Meta) {
model.dependsOn("fitscan", meta, "fitscan")
}
override fun getName(): String {
return "scansum"
}
@TypedActionDef(name = "sterileSummary", inputType = FitResult::class, outputType = Table::class)
private inner class FitSummaryAction : ManyToOneAction<FitResult, Table>() {
override fun execute(context: Context, nodeName: String, input: Map<String, FitResult>, meta: Laminate): Table {
val builder = ListTable.Builder("m", "U2", "U2err", "U2limit", "E0", "trap")
input.forEach { key, fitRes ->
val pars = fitRes.parameters
val u2Val = pars.getDouble("U2")!! / pars.getError("U2")
val limit: Double
if (Math.abs(u2Val) < 3) {
limit = UpperLimitGenerator.getConfidenceLimit(u2Val) * pars.getError("U2")
} else {
limit = java.lang.Double.NaN
}
builder.row(
Math.sqrt(pars.getValue("msterile2").doubleValue()),
pars.getValue("U2"),
pars.getError("U2"),
limit,
pars.getValue("E0"),
pars.getValue("trap"))
}
val res = TableTransform.sort(builder.build(), "m", true)
output(context, nodeName) { stream -> NumassUtils.write(stream, meta, res) }
return res
}
}
}

View File

@ -0,0 +1,86 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package inr.numass.tasks
import hep.dataforge.data.DataNode
import hep.dataforge.data.DataTree
import hep.dataforge.meta.Meta
import hep.dataforge.meta.MetaBuilder
import hep.dataforge.stat.fit.FitAction
import hep.dataforge.stat.fit.FitResult
import hep.dataforge.tables.Table
import hep.dataforge.values.ListValue
import hep.dataforge.values.Value
import hep.dataforge.workspace.tasks.AbstractTask
import hep.dataforge.workspace.tasks.TaskModel
import java.util.stream.Collectors
/**
* @author Alexander Nozik
*/
class NumassFitScanTask : AbstractTask<FitResult>() {
override fun run(model: TaskModel, data: DataNode<*>): DataNode<FitResult> {
val config = model.meta()
val scanParameter = config.getString("parameter", "msterile2")
val scanValues: Value = if (config.hasValue("masses")) {
ListValue(config.getValue("masses")
.listValue().stream()
.map { it -> Math.pow(it.doubleValue() * 1000, 2.0) }
.collect(Collectors.toList<Any>())
)
} else {
config.getValue("values", Value.of("[2.5e5, 1e6, 2.25e6, 4e6, 6.25e6, 9e6]"))
}
val action = FitAction()
val resultBuilder = DataTree.builder(FitResult::class.java)
val sourceNode = data.checked(Table::class.java)
//do fit
val fitConfig = config.getMeta("fit")
sourceNode.dataStream().forEach { table ->
for (i in 0 until scanValues.listValue().size) {
val `val` = scanValues.listValue()[i]
val overrideMeta = MetaBuilder(fitConfig)
val resultName = String.format("%s[%s=%s]", table.name, scanParameter, `val`.stringValue())
// overrideMeta.setValue("@resultName", String.format("%s[%s=%s]", table.getName(), scanParameter, val.stringValue()));
if (overrideMeta.hasMeta("params." + scanParameter)) {
overrideMeta.setValue("params.$scanParameter.value", `val`)
} else {
overrideMeta.getMetaList("params.param").stream()
.filter { par -> par.getString("name") == scanParameter }.forEach { par -> par.setValue("value", `val`) }
}
// Data<Table> newData = new Data<Table>(data.getGoal(),data.type(),overrideMeta);
val node = action.run(model.context, DataNode.of(resultName, table, Meta.empty()), overrideMeta)
resultBuilder.putData(table.name + ".fit_" + i, node.data)
}
}
return resultBuilder.build()
}
override fun buildModel(model: TaskModel.Builder, meta: Meta) {
model.configure(meta.getMetaOrEmpty("scan"))
model.configure { it -> it.putNode(meta.getMetaOrEmpty("fit")) }
when {
meta.hasMeta("filter") -> model.dependsOn("filter", meta, "prepare")
meta.hasMeta("empty") -> model.dependsOn("subtractEmpty", meta, "prepare")
else -> model.dependsOn("prepare", meta, "prepare")
}
}
override fun getName(): String {
return "fitscan"
}
}

View File

@ -0,0 +1,51 @@
/*
* Copyright 2015 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.tasks
import hep.dataforge.actions.Action
import hep.dataforge.data.DataNode
import hep.dataforge.meta.Meta
import hep.dataforge.stat.fit.FitState
import hep.dataforge.tables.Table
import hep.dataforge.workspace.tasks.SingleActionTask
import hep.dataforge.workspace.tasks.TaskModel
import inr.numass.actions.SummaryAction
/**
* Created by darksnake on 16-Sep-16.
*/
class NumassFitSummaryTask : SingleActionTask<FitState, Table>() {
override fun getName(): String {
return "summary"
}
override fun getAction(model: TaskModel): Action<FitState, Table> {
return SummaryAction()
}
override fun gatherNode(data: DataNode<*>): DataNode<FitState> {
return data.getCheckedNode("fit", FitState::class.java)
}
override fun transformMeta(model: TaskModel): Meta {
return model.meta().getMeta("summary")
}
override fun buildModel(model: TaskModel.Builder, meta: Meta) {
model.dependsOn("fit", meta, "fit")
}
}

View File

@ -0,0 +1,61 @@
/*
* Copyright 2015 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.tasks
import hep.dataforge.actions.Action
import hep.dataforge.actions.ActionUtils
import hep.dataforge.data.DataNode
import hep.dataforge.meta.Meta
import hep.dataforge.plotfit.PlotFitResultAction
import hep.dataforge.stat.fit.FitAction
import hep.dataforge.stat.fit.FitResult
import hep.dataforge.tables.Table
import hep.dataforge.workspace.tasks.SingleActionTask
import hep.dataforge.workspace.tasks.TaskModel
/**
* Created by darksnake on 16-Sep-16.
*/
class NumassFitTask : SingleActionTask<Table, FitResult>() {
override fun getName(): String {
return "fit"
}
override fun gatherNode(data: DataNode<*>): DataNode<Table> {
return data.checked(Table::class.java)
}
override fun validate(model: TaskModel) {
if (model.meta().isEmpty) {
throw RuntimeException("Fit element not found in model")
}
}
override fun getAction(model: TaskModel): Action<Table, FitResult> {
val action = FitAction()
return if (model.meta().getBoolean("frame", false)) {
ActionUtils.compose(action, PlotFitResultAction())
} else {
action
}
}
override fun buildModel(model: TaskModel.Builder, meta: Meta) {
model.dependsOn("transform", meta);
}
}

View File

@ -0,0 +1,77 @@
package inr.numass.tasks
import hep.dataforge.actions.Action
import hep.dataforge.actions.OneToOneAction
import hep.dataforge.context.Context
import hep.dataforge.data.DataNode
import hep.dataforge.description.TypedActionDef
import hep.dataforge.meta.Laminate
import hep.dataforge.meta.Meta
import hep.dataforge.tables.Table
import hep.dataforge.tables.TableTransform
import hep.dataforge.values.ValueType
import hep.dataforge.values.Values
import hep.dataforge.workspace.tasks.SingleActionTask
import hep.dataforge.workspace.tasks.TaskModel
import inr.numass.data.api.NumassPoint
import inr.numass.utils.ExpressionUtils
import java.util.*
/**
* Created by darksnake on 13-Aug-16.
*/
class NumassTableFilterTask : SingleActionTask<Table, Table>() {
override fun getName(): String {
return "filter"
}
override fun gatherNode(data: DataNode<*>): DataNode<Table> {
return data.checked(Table::class.java)
}
override fun buildModel(model: TaskModel.Builder, meta: Meta) {
if (meta.hasMeta("empty")) {
model.dependsOn("did", meta)
} else {
model.dependsOn("transform", meta)
}
}
override fun getAction(model: TaskModel): Action<Table, Table> {
return FilterTableAction()
}
@TypedActionDef(name = "filterTable", inputType = Table::class, outputType = Table::class)
private inner class FilterTableAction : OneToOneAction<Table, Table>() {
override fun execute(context: Context, name: String, input: Table, inputMeta: Laminate): Table {
if (inputMeta.hasValue("from") || inputMeta.hasValue("to")) {
val uLo = inputMeta.getDouble("from", 0.0)!!
val uHi = inputMeta.getDouble("to", java.lang.Double.POSITIVE_INFINITY)!!
getLogger(context, inputMeta).debug("Filtering finished")
return TableTransform.filter(input, NumassPoint.HV_KEY, uLo, uHi)
} else if (inputMeta.hasValue("condition")) {
return TableTransform.filter(input) { ExpressionUtils.condition(inputMeta.getString("condition"), unbox(it)) }
} else {
throw RuntimeException("No filtering condition specified")
}
}
}
private fun unbox(dp: Values): Map<String, Any?> {
val res = HashMap<String, Any?>()
for (field in dp.names) {
val value = dp.getValue(field)
val obj: Any? = when (value.type) {
ValueType.BOOLEAN -> value.booleanValue()
ValueType.NUMBER -> value.doubleValue()
ValueType.STRING -> value.stringValue()
ValueType.TIME -> value.timeValue()
ValueType.NULL -> null
}
res.put(field, obj)
}
return res
}
}

View File

@ -5,11 +5,12 @@ import hep.dataforge.data.DataSet
import hep.dataforge.data.DataTree import hep.dataforge.data.DataTree
import hep.dataforge.data.DataUtils import hep.dataforge.data.DataUtils
import hep.dataforge.description.ValueDef import hep.dataforge.description.ValueDef
import hep.dataforge.io.ColumnedDataWriter
import hep.dataforge.kodex.configure import hep.dataforge.kodex.configure
import hep.dataforge.kodex.fx.plots.PlotManager import hep.dataforge.kodex.fx.plots.PlotManager
import hep.dataforge.kodex.fx.plots.plus import hep.dataforge.kodex.fx.plots.plus
import hep.dataforge.kodex.task import hep.dataforge.kodex.task
import hep.dataforge.meta.Meta
import hep.dataforge.meta.MetaUtils
import hep.dataforge.plots.PlotFrame import hep.dataforge.plots.PlotFrame
import hep.dataforge.plots.data.DataPlot import hep.dataforge.plots.data.DataPlot
import hep.dataforge.plots.jfreechart.JFreeChartFrame import hep.dataforge.plots.jfreechart.JFreeChartFrame
@ -20,6 +21,7 @@ import hep.dataforge.values.ValueType
import inr.numass.NumassUtils import inr.numass.NumassUtils
import inr.numass.actions.MergeDataAction import inr.numass.actions.MergeDataAction
import inr.numass.actions.MergeDataAction.MERGE_NAME import inr.numass.actions.MergeDataAction.MERGE_NAME
import inr.numass.actions.TransformDataAction
import inr.numass.addSetMarkers import inr.numass.addSetMarkers
import inr.numass.data.analyzers.SmartAnalyzer import inr.numass.data.analyzers.SmartAnalyzer
import inr.numass.data.api.NumassSet import inr.numass.data.api.NumassSet
@ -89,7 +91,7 @@ val monitorTableTask = task("monitor") {
val analyzeTask = task("analyze") { val analyzeTask = task("analyze") {
model { meta -> model { meta ->
dependsOn("select", meta); dependsOn("select", meta);
configure(meta.getMetaOrEmpty("analyzer")) configure(MetaUtils.optEither(meta, "analyzer", "prepare").orElse(Meta.empty()))
} }
pipe<NumassSet, Table> { pipe<NumassSet, Table> {
result { set -> result { set ->
@ -120,7 +122,7 @@ val mergeEmptyTask = task("empty") {
.removeNode("data") .removeNode("data")
.removeNode("empty") .removeNode("empty")
.setNode("data", meta.getMeta("empty")) .setNode("data", meta.getMeta("empty"))
.setValue(MERGE_NAME, meta.getString(MERGE_NAME, "") + "_empty"); .setValue("merge." + MERGE_NAME, meta.getString("merge." + MERGE_NAME, "") + "_empty");
dependsOn("merge", newMeta) dependsOn("merge", newMeta)
} }
transform<Table, Table> { data -> transform<Table, Table> { data ->
@ -138,7 +140,7 @@ val subtractEmptyTask = task("dif") {
dependsOn("merge", meta, "data") dependsOn("merge", meta, "data")
dependsOn("empty", meta, "empty") dependsOn("empty", meta, "empty")
} }
transform<Table,Table> { data -> transform<Table, Table> { data ->
val builder = DataTree.builder(Table::class.java) val builder = DataTree.builder(Table::class.java)
val rootNode = data.getCheckedNode<Table>("data", Table::class.java) val rootNode = data.getCheckedNode<Table>("data", Table::class.java)
val empty = data.getCheckedNode<Table>("empty", Table::class.java).data val empty = data.getCheckedNode<Table>("empty", Table::class.java).data
@ -149,9 +151,9 @@ val subtractEmptyTask = task("dif") {
res.goal.onComplete { r, _ -> res.goal.onComplete { r, _ ->
if (r != null) { if (r != null) {
val out = context.io().out("numass.merge", input.name + "_subtract") context.io().out("numass.merge", input.name + "_subtract").use {
ColumnedDataWriter.writeTable(out, r, NumassUtils.write(it, empty.meta(), r)
input.meta().builder.setNode("empty", empty.meta()).toString()) }
} }
} }
@ -160,3 +162,19 @@ val subtractEmptyTask = task("dif") {
builder.build() builder.build()
} }
} }
val transformTask = task("transform") {
model { meta ->
if (meta.hasMeta("merge")) {
if (meta.hasMeta("empty")) {
dependsOn("dif", meta)
} else {
dependsOn("merge", meta);
}
} else {
dependsOn("analyze", meta);
}
configure(MetaUtils.optEither(meta, "transform", "prepare").orElse(Meta.empty()))
}
action<Table, Table>(TransformDataAction());
}