[no commit message]

This commit is contained in:
Alexander Nozik 2016-03-27 20:40:50 +03:00
parent 6d938f3380
commit 63ca107233
19 changed files with 159 additions and 197 deletions

View File

@ -54,7 +54,8 @@ new MINUITPlugin().startGlobal();
FitManager fm = new FitManager();
ResolutionFunction resolution = new ResolutionFunction(8.3e-5);
resolution.setTailFunction(ResolutionFunction.getRealTail());
//resolution.setTailFunction(ResolutionFunction.getRealTail());
resolution.setTailFunction(ResolutionFunction.getAngledTail(0.00325));
ModularTritiumSpectrum beta = new ModularTritiumSpectrum(resolution, 18395d, 18580d, null);
beta.setCaching(false);
@ -64,9 +65,9 @@ XYModel model = new XYModel("tritium", spectrum, new SpectrumDataAdapter());
ParamSet allPars = new ParamSet();
allPars.setPar("N", 6e7, 1e5, 0, Double.POSITIVE_INFINITY);
allPars.setPar("N", 6e9, 1e5, 0, Double.POSITIVE_INFINITY);
allPars.setPar("bkg", 2, 0.1 );
allPars.setPar("bkg", 0.002, 0.005 );
allPars.setPar("E0", 18575.0, 0.1 );
@ -85,18 +86,18 @@ allPars.setPar("trap", 1, 0.01, 0d, Double.POSITIVE_INFINITY);
int seed = 12316
SpectrumGenerator generator = new SpectrumGenerator(model, allPars, seed);
def config = DataModelUtils.getUniformSpectrumConfiguration(18400d, 18580, 1e7, 60)
def config = DataModelUtils.getUniformSpectrumConfiguration(18530d, 18580, 1e7, 60)
//def config = DataModelUtils.getSpectrumConfigurationFromResource("/data/run23.cfg")
ListPointSet data = generator.generateExactData(config);
FitState state = new FitState(data, model, allPars);
println("Simulating data with real tail. Seed = ${seed}")
println("Simulating data with real tail")
println("Fitting data with real parameters")
FitState res = fm.runTask(state, "QOW", FitTask.TASK_RUN, "N", "bkg","E0", "mnu2");
FitState res = fm.runTask(state, "QOW", FitTask.TASK_RUN, "N", "bkg", "E0", "mnu2");
res.print(out());
def mnu2 = res.getParameters().getValue("mnu2");
@ -104,7 +105,7 @@ def mnu2 = res.getParameters().getValue("mnu2");
println("Setting constant tail and fitting")
resolution.setTailFunction(ResolutionFunction.getConstantTail());
res = fm.runTask(state, "QOW", FitTask.TASK_RUN, "N", "bkg","E0", "mnu2");
res = fm.runTask(state, "QOW", FitTask.TASK_RUN, "N", "bkg","E0","mnu2");
res.print(out());
def diff = res.getParameters().getValue("mnu2") - mnu2;

View File

@ -25,6 +25,7 @@ import hep.dataforge.description.TypedActionDef;
import hep.dataforge.description.ValueDef;
import hep.dataforge.exceptions.ContentException;
import hep.dataforge.io.log.Logable;
import hep.dataforge.meta.Laminate;
import hep.dataforge.meta.Meta;
import hep.dataforge.plots.PlotsPlugin;
import hep.dataforge.plots.XYPlotFrame;
@ -42,12 +43,8 @@ import hep.dataforge.points.PointSet;
@ValueDef(name = "plotTitle", def = "", info = "The title of the plot.")
public class PlotFitResultAction extends OneToOneAction<FitState, FitState> {
public PlotFitResultAction(Context context, Meta annotation) {
super(context, annotation);
}
@Override
protected FitState execute(Logable log, String name, Meta metaData, FitState input) {
protected FitState execute(Context context,Logable log, String name, Laminate metaData, FitState input) {
PointSet data = input.getDataSet();
if (!(input.getModel() instanceof XYModel)) {
@ -68,7 +65,7 @@ public class PlotFitResultAction extends OneToOneAction<FitState, FitState> {
UnivariateFunction function = (double x) -> model.getSpectrum().value(x, input.getParameters());
XYPlotFrame frame = (XYPlotFrame) PlotsPlugin
.buildFrom(getContext()).buildPlotFrame(getName(), name,
.buildFrom(context).buildPlotFrame(getName(), name,
metaData.getNode("plot", null));
//JFreeChartFrame.drawFrame(reader.getString("plotTitle", "Fit result plot for "+input.getName()), null);

View File

@ -15,7 +15,7 @@
*/
package inr.numass;
import hep.dataforge.actions.RunManager;
import hep.dataforge.actions.ActionUtils;
import hep.dataforge.context.Context;
import static hep.dataforge.context.GlobalContext.out;
import hep.dataforge.data.DataNode;
@ -42,6 +42,13 @@ import org.apache.commons.cli.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
/**
*
@ -107,7 +114,7 @@ public class Main {
applyCLItoContext(line, context);
return RunManager.executeAction(context, config);
return ActionUtils.runConfig(context, config);
} else {
Workbench.main(args);
return null;

View File

@ -12,6 +12,7 @@ import hep.dataforge.points.ListPointSet;
import hep.dataforge.points.MapPoint;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.io.log.Logable;
import hep.dataforge.meta.Laminate;
import hep.dataforge.meta.Meta;
import java.util.ArrayList;
import java.util.List;
@ -25,12 +26,8 @@ import hep.dataforge.points.PointSet;
@TypedActionDef(name = "adjustErrors", inputType = PointSet.class, outputType = PointSet.class)
public class AdjustErrorsAction extends OneToOneAction<PointSet, PointSet> {
public AdjustErrorsAction(Context context, Meta annotation) {
super(context, annotation);
}
@Override
protected PointSet execute(Logable log, String name,Meta meta, PointSet input) {
protected PointSet execute(Context context, Logable log, String name, Laminate meta, PointSet input) {
List<DataPoint> points = new ArrayList<>();
for (DataPoint dp : input) {
points.add(evalPoint(meta, dp));

View File

@ -21,7 +21,7 @@ import hep.dataforge.description.TypedActionDef;
import hep.dataforge.description.ValueDef;
import hep.dataforge.exceptions.ContentException;
import hep.dataforge.io.log.Logable;
import hep.dataforge.meta.Meta;
import hep.dataforge.meta.Laminate;
import inr.numass.data.RawNMFile;
import inr.numass.data.RawNMPoint;
import inr.numass.debunch.DebunchReport;
@ -40,19 +40,15 @@ import java.io.PrintWriter;
@ValueDef(name = "maxcr", type = "NUMBER", def = "100", info = "Maximum count rate for debunching")
public class DebunchAction extends OneToOneAction<RawNMFile, RawNMFile> {
public DebunchAction(Context context, Meta an) {
super(context, an);
}
@Override
protected RawNMFile execute(Logable log, String name, Meta reader, RawNMFile source) throws ContentException {
protected RawNMFile execute(Context context, Logable log, String name, Laminate meta, RawNMFile source) throws ContentException {
log.log("File {} started", source.getName());
int upper = source.meta().getInt("upperchanel", this.meta().getInt("upperchanel", RawNMPoint.MAX_CHANEL));
int lower = source.meta().getInt("lowerchanel", this.meta().getInt("lowerchanel", 0));
double rejectionprob = source.meta().getDouble("rejectprob", this.meta().getDouble("rejectprob", 1e-5));
double framelength = source.meta().getDouble("framelength", this.meta().getDouble("framelength", 5));
double maxCR = source.meta().getDouble("maxcr", this.meta().getDouble("maxcr", 100d));
int upper = meta.getInt("upperchanel", RawNMPoint.MAX_CHANEL);
int lower = meta.getInt("lowerchanel", 0);
double rejectionprob = meta.getDouble("rejectprob", 1e-5);
double framelength = meta.getDouble("framelength", 5);
double maxCR = meta.getDouble("maxcr", 100d);
RawNMFile res = new RawNMFile(source.getName());
res.setHead(source.getHead());
@ -71,7 +67,7 @@ public class DebunchAction extends OneToOneAction<RawNMFile, RawNMFile> {
});
log.log("File {} completed", source.getName());
log.getLog().print(new PrintWriter(buildActionOutput(name)));
log.getLog().print(new PrintWriter(buildActionOutput(context, name)));
// res.configure(source.meta());
return res;

View File

@ -21,6 +21,7 @@ import hep.dataforge.description.TypedActionDef;
import hep.dataforge.exceptions.ContentException;
import hep.dataforge.io.ColumnedDataWriter;
import hep.dataforge.io.log.Logable;
import hep.dataforge.meta.Laminate;
import hep.dataforge.meta.Meta;
import inr.numass.data.NMFile;
import inr.numass.data.NMPoint;
@ -33,17 +34,13 @@ import java.io.OutputStream;
@TypedActionDef(name = "findBorder", inputType = NMFile.class, outputType = NMFile.class)
public class FindBorderAction extends OneToOneAction<NMFile, NMFile> {
public FindBorderAction(Context context, Meta an) {
super(context, an);
}
@Override
protected NMFile execute(Logable log, String name, Meta reader, NMFile source) throws ContentException {
protected NMFile execute(Context context, Logable log, String name, Laminate meta, NMFile source) throws ContentException {
log.log("File {} started", source.getName());
int upperBorder = meta().getInt("upper", 4096);
int lowerBorder = meta().getInt("lower", 0);
double substractReference = meta().getDouble("reference", 0);
int upperBorder = meta.getInt("upper", 4096);
int lowerBorder = meta.getInt("lower", 0);
double substractReference = meta.getDouble("reference", 0);
NMPoint referencePoint = null;
if (substractReference > 0) {
@ -55,7 +52,7 @@ public class FindBorderAction extends OneToOneAction<NMFile, NMFile> {
BorderData bData = new BorderData(source, upperBorder, lowerBorder, referencePoint);
OutputStream stream = buildActionOutput(name);
OutputStream stream = buildActionOutput(context, name);
ColumnedDataWriter.writeDataSet(stream, bData, String.format("%s : lower = %d upper = %d", source.getName(), lowerBorder, upperBorder));

View File

@ -35,7 +35,6 @@ import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
*
@ -48,17 +47,13 @@ public class MergeDataAction extends ManyToOneAction<PointSet, PointSet> {
public static final String MERGE_NAME = "mergeName";
public static String[] parnames = {"Uset", "Uread", "Length", "Total", "Window", "Corrected", "CR", "CRerr"};
public MergeDataAction(Context context, Meta an) {
super(context, an);
}
@Override
@SuppressWarnings("unchecked")
protected List<DataNode<PointSet>> buildGroups(DataNode input) {
Meta meta = inputMeta(input.meta());
protected List<DataNode<PointSet>> buildGroups(Context context, DataNode input, Meta actionMeta) {
Meta meta = inputMeta(context, input.meta(), actionMeta);
List<DataNode<PointSet>> groups;
if (meta.hasValue("grouping.byValue")) {
groups = super.buildGroups(input);
groups = super.buildGroups(context, input, actionMeta);
} else {
groups = GroupBuilder.byValue(MERGE_NAME, meta.getString(MERGE_NAME, "merge")).group(input);
}
@ -66,19 +61,14 @@ public class MergeDataAction extends ManyToOneAction<PointSet, PointSet> {
}
@Override
protected PointSet execute(Logable log, DataNode<PointSet> input) {
return mergeOne(log, input);
}
private PointSet mergeOne(Logable log, DataNode<PointSet> input) {
List<PointSet> data = input.stream().<PointSet>map(item -> item.getValue().get()).collect(Collectors.toList());
PointSet res = mergeDataSets(input.getName(), data);
protected PointSet execute(Context context, Logable log, String nodeName, Map<String, PointSet> data, Meta meta) {
PointSet res = mergeDataSets(nodeName, data.values());
return res.sort("Uset", true);
}
@Override
protected void afterGroup(Logable log, String groupName, Meta outputMeta, PointSet output) {
OutputStream stream = buildActionOutput(groupName);
protected void afterGroup(Context context, Logable log, String groupName, Meta outputMeta, PointSet output) {
OutputStream stream = buildActionOutput(context, groupName);
ColumnedDataWriter.writeDataSet(stream, output, outputMeta.toString());
}
@ -96,7 +86,7 @@ public class MergeDataAction extends ManyToOneAction<PointSet, PointSet> {
} else {
return newPath;
}
});
});
MetaBuilder builder = super.outputMeta(input);
/*

View File

@ -15,7 +15,6 @@
*/
package inr.numass.actions;
import hep.dataforge.actions.ActionResult;
import hep.dataforge.actions.OneToOneAction;
import hep.dataforge.context.Context;
import hep.dataforge.points.DataPoint;
@ -26,6 +25,7 @@ import hep.dataforge.description.ValueDef;
import hep.dataforge.exceptions.ContentException;
import hep.dataforge.io.ColumnedDataWriter;
import hep.dataforge.io.log.Logable;
import hep.dataforge.meta.Laminate;
import hep.dataforge.meta.Meta;
import hep.dataforge.values.Value;
import java.io.OutputStream;
@ -51,15 +51,12 @@ public class MonitorCorrectAction extends OneToOneAction<PointSet, PointSet> {
private static final String[] monitorNames = {"Timestamp", "Total", "CR", "CRerr"};
CopyOnWriteArrayList<DataPoint> monitorPoints = new CopyOnWriteArrayList<>();
public MonitorCorrectAction(Context context, Meta an) {
super(context, an);
}
//FIXME remove from state
@Override
protected PointSet execute(Logable log, String name, Meta reader, PointSet sourceData) throws ContentException {
protected PointSet execute(Context context, Logable log, String name, Laminate meta, PointSet sourceData) throws ContentException {
double monitor = reader.getDouble("monitorPoint", Double.NaN);
double monitor = meta.getDouble("monitorPoint", Double.NaN);
TreeMap<LocalDateTime, DataPoint> index = getMonitorIndex(monitor, sourceData);
if (index.isEmpty()) {
@ -116,7 +113,7 @@ public class MonitorCorrectAction extends OneToOneAction<PointSet, PointSet> {
point.putValue("Corrected", Value.of(dp.getValue("Corrected").doubleValue() / corrFactor));
point.putValue("CRerr", Value.of(err));
}
if (meta().getBoolean("calculateRelative", false)) {
if (meta.getBoolean("calculateRelative", false)) {
point.putValue("relCR", point.getValue("CR").doubleValue() / norm);
point.putValue("relCRerr", point.getValue("CRerr").doubleValue() / norm);
}
@ -133,7 +130,7 @@ public class MonitorCorrectAction extends OneToOneAction<PointSet, PointSet> {
// }
PointSet data = new ListPointSet(dataList);
OutputStream stream = buildActionOutput(name);
OutputStream stream = buildActionOutput(context, name);
ColumnedDataWriter.writeDataSet(stream, data, head);
@ -141,14 +138,14 @@ public class MonitorCorrectAction extends OneToOneAction<PointSet, PointSet> {
}
@Override
protected void afterAction(String name, PointSet res) {
printMonitorData();
super.afterAction(name, res); //To change body of generated methods, choose Tools | Templates.
protected void afterAction(Context context, String name, PointSet res, Laminate meta) {
printMonitorData(context, meta);
super.afterAction(context, name, res, meta);
}
private void printMonitorData() {
String monitorFileName = meta().getString("monitorFile", "monitor");
OutputStream stream = buildActionOutput(monitorFileName);
private void printMonitorData(Context context, Meta meta) {
String monitorFileName = meta.getString("monitorFile", "monitor");
OutputStream stream = buildActionOutput(context, monitorFileName);
ListPointSet data = new ListPointSet(monitorPoints);
ColumnedDataWriter.writeDataSet(stream, data.sort("Timestamp", true), "Monitor points", monitorNames);
}

View File

@ -27,6 +27,7 @@ import hep.dataforge.exceptions.ContentException;
import hep.dataforge.io.ColumnedDataWriter;
import hep.dataforge.io.XMLMetaWriter;
import hep.dataforge.io.log.Logable;
import hep.dataforge.meta.Laminate;
import hep.dataforge.meta.Meta;
import inr.numass.data.NMFile;
import inr.numass.data.NMPoint;
@ -50,24 +51,20 @@ public class PrepareDataAction extends OneToOneAction<NMFile, PointSet> {
public static String[] parnames = {"Uset", "Uread", "Length", "Total", "Window", "Corrected", "CR", "CRerr", "Timestamp"};
public PrepareDataAction(Context context, Meta an) {
super(context, an);
}
private int getLowerBorder(Meta source, double Uset) throws ContentException {
double b = source.getDouble("lowerWindow", this.meta().getDouble("lowerWindow", 0));
double a = source.getDouble("lowerWindowSlope", this.meta().getDouble("lowerWindowSlope", 0));
private int getLowerBorder(Meta meta, double Uset) throws ContentException {
double b = meta.getDouble("lowerWindow", 0);
double a = meta.getDouble("lowerWindowSlope", 0);
return (int) (b + Uset * a);
}
@Override
protected ListPointSet execute(Logable log, String name, Meta reader, NMFile dataFile) {
protected ListPointSet execute(Context context, Logable log, String name, Laminate meta, NMFile dataFile) {
// log.logString("File %s started", dataFile.getName());
int upper = dataFile.meta().getInt("upperWindow", this.meta().getInt("upperWindow", RawNMPoint.MAX_CHANEL - 1));
int upper = meta.getInt("upperWindow", RawNMPoint.MAX_CHANEL - 1);
double deadTime = dataFile.meta().getDouble("deadTime", this.meta().getDouble("deadTime", 0));
double deadTime = meta.getDouble("deadTime", 0);
// double bkg = source.meta().getDouble("background", this.meta().getDouble("background", 0));
List<DataPoint> dataList = new ArrayList<>();
@ -77,7 +74,7 @@ public class PrepareDataAction extends OneToOneAction<NMFile, PointSet> {
double Uset = point.getUset();
double Uread = point.getUread();
double time = point.getLength();
int a = getLowerBorder(dataFile.meta(), Uset);
int a = getLowerBorder(meta, Uset);
int b = Math.min(upper, RawNMPoint.MAX_CHANEL);
// analyzer.setMonitorCorrector(corrector);
@ -110,11 +107,11 @@ public class PrepareDataAction extends OneToOneAction<NMFile, PointSet> {
} else {
head = dataFile.getName();
}
head = head + "\n" + new XMLMetaWriter().writeString(meta(), null) + "\n";
head = head + "\n" + new XMLMetaWriter().writeString(meta, null) + "\n";
ListPointSet data = new ListPointSet(dataList, format);
OutputStream stream = buildActionOutput(name);
OutputStream stream = buildActionOutput(context, name);
ColumnedDataWriter.writeDataSet(stream, data, head);
// log.logString("File %s completed", dataFile.getName());

View File

@ -22,7 +22,7 @@ import hep.dataforge.description.TypedActionDef;
import hep.dataforge.description.ValueDef;
import hep.dataforge.exceptions.ContentException;
import hep.dataforge.io.log.Logable;
import hep.dataforge.meta.Meta;
import hep.dataforge.meta.Laminate;
import static inr.numass.NumassIO.getNumassData;
import inr.numass.data.NMFile;
import inr.numass.data.RawNMFile;
@ -41,21 +41,20 @@ import java.io.File;
@NodeDef(name = "debunch", target = "class::inr.numass.actions.DebunchAction", info = "If given, governs debunching")
public class ReadNumassDataAction extends OneToOneAction<File, NMFile> {
public ReadNumassDataAction(Context context, Meta an) {
super(context, an);
}
@Override
protected NMFile execute(Logable log, String name, Meta reader, File source) throws ContentException {
protected NMFile execute(Context context, Logable log, String name, Laminate meta, File source) throws ContentException {
// log.logString("File '%s' started", source.getName());
RawNMFile raw = getNumassData(source, meta());
if (meta().getBoolean("paw", false)) {
raw.generatePAW(buildActionOutput(name + ".paw"));
RawNMFile raw = getNumassData(source, meta);
if (meta.getBoolean("paw", false)) {
raw.generatePAW(buildActionOutput(context, name + ".paw"));
}
if (meta().hasNode("debunch")) {
DebunchAction debunch = new DebunchAction(getContext(), meta().getNode("debunch"));
raw = debunch.execute(log, name, null, raw);
if (meta.getNodeNames(false).contains("debunch")) {
DebunchAction debunch = new DebunchAction();
Laminate laminate = new Laminate(meta.getNode("debunch"))
.setValueContext(context)
.setDescriptor(debunch.getDescriptor());
raw = debunch.execute(context, log, name, laminate, raw);
}
NMFile result = new NMFile(raw);

View File

@ -33,6 +33,7 @@ import hep.dataforge.maths.GridCalculator;
import hep.dataforge.maths.NamedDoubleSet;
import hep.dataforge.maths.NamedMatrix;
import hep.dataforge.maths.integration.UnivariateIntegrator;
import hep.dataforge.meta.Laminate;
import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.plots.PlotsPlugin;
@ -65,12 +66,8 @@ public class ShowLossSpectrumAction extends OneToOneAction<FitState, FitState> {
private static final String[] names = {"X", "exPos", "ionPos", "exW", "ionW", "exIonRatio"};
public ShowLossSpectrumAction(Context context, Meta annotation) {
super(context, annotation);
}
@Override
protected FitState execute(Logable log, String name, Meta reader, FitState input) {
protected FitState execute(Context context, Logable log, String name, Laminate meta, FitState input) {
ParamSet pars = input.getParameters();
if (!pars.names().contains(names)) {
LoggerFactory.getLogger(getClass()).error("Wrong input FitState. Must be loss spectrum fit.");
@ -79,7 +76,7 @@ public class ShowLossSpectrumAction extends OneToOneAction<FitState, FitState> {
UnivariateFunction scatterFunction;
boolean calculateRatio = false;
XYPlotFrame frame = (XYPlotFrame) PlotsPlugin.buildFrom(getContext())
XYPlotFrame frame = (XYPlotFrame) PlotsPlugin.buildFrom(context)
.buildPlotFrame(getName(), name + ".loss",
new MetaBuilder("plot")
.setValue("plotTitle", "Differential scattering crossection for " + name)
@ -104,15 +101,15 @@ public class ShowLossSpectrumAction extends OneToOneAction<FitState, FitState> {
double ionRatio = -1;
double ionRatioError = -1;
if (calculateRatio) {
threshold = reader.getDouble("ionThreshold", 17);
threshold = meta.getDouble("ionThreshold", 17);
ionRatio = calcultateIonRatio(pars, threshold);
log.log("The ionization ratio (using threshold {}) is {}", threshold, ionRatio);
ionRatioError = calultateIonRatioError(name, input, threshold);
ionRatioError = calultateIonRatioError(context, name, input, threshold);
log.log("the ionization ration standard deviation (using threshold {}) is {}", threshold, ionRatioError);
}
if (reader.getBoolean("printResult", false)) {
PrintWriter writer = new PrintWriter(new OutputStreamWriter(buildActionOutput(name), Charset.forName("UTF-8")));
if (meta.getBoolean("printResult", false)) {
PrintWriter writer = new PrintWriter(new OutputStreamWriter(buildActionOutput(context, name), Charset.forName("UTF-8")));
// writer.println("*** FIT PARAMETERS ***");
input.print(writer);
// for (Param param : pars.getSubSet(names).getParams()) {
@ -168,7 +165,7 @@ public class ShowLossSpectrumAction extends OneToOneAction<FitState, FitState> {
writer.println();
PrintFunction.printFunctionSimple(writer, scatterFunction, 0, 100, 500);
if (meta().getBoolean("showSpread", false)) {
if (meta.getBoolean("showSpread", false)) {
writer.println("***SPECTRUM SPREAD***");
writer.println();
@ -208,14 +205,14 @@ public class ShowLossSpectrumAction extends OneToOneAction<FitState, FitState> {
return exProb / ionProb;
}
public double calultateIonRatioError(String dataNeme, FitState state, double threshold) {
public double calultateIonRatioError(Context context, String dataNeme, FitState state, double threshold) {
ParamSet parameters = state.getParameters().getSubSet(new String[]{"exPos", "ionPos", "exW", "ionW", "exIonRatio"});
NamedMatrix covariance = state.getCovariance();
return calultateIonRatioError(dataNeme, parameters, covariance, threshold);
return calultateIonRatioError(context, dataNeme, parameters, covariance, threshold);
}
@SuppressWarnings("Unchecked")
public double calultateIonRatioError(String name, NamedDoubleSet parameters, NamedMatrix covariance, double threshold) {
public double calultateIonRatioError(Context context, String name, NamedDoubleSet parameters, NamedMatrix covariance, double threshold) {
int number = 10000;
double[] res = new GaussianParameterGenerator(parameters, covariance)
@ -227,7 +224,7 @@ public class ShowLossSpectrumAction extends OneToOneAction<FitState, FitState> {
Histogram hist = new Histogram(0.3, 0.5, 0.002);
hist.fill(res);
XYPlotFrame frame = (XYPlotFrame) PlotsPlugin.buildFrom(getContext())
XYPlotFrame frame = (XYPlotFrame) PlotsPlugin.buildFrom(context)
.buildPlotFrame(getName(), name + ".ionRatio",
new MetaBuilder("plot").setValue("plotTitle", "Ion ratio Distribution for " + name)
);

View File

@ -21,6 +21,7 @@ import hep.dataforge.description.TypedActionDef;
import hep.dataforge.exceptions.ContentException;
import hep.dataforge.io.ColumnedDataWriter;
import hep.dataforge.io.log.Logable;
import hep.dataforge.meta.Laminate;
import hep.dataforge.meta.Meta;
import hep.dataforge.plots.fx.FXPlotUtils;
import hep.dataforge.plots.jfreechart.JFreeChartFrame;
@ -45,28 +46,24 @@ import org.jfree.ui.RectangleEdge;
@TypedActionDef(name = "showSpectrum", inputType = NMFile.class, outputType = NMFile.class)
public class ShowSpectrumAction extends OneToOneAction<NMFile, NMFile> {
public ShowSpectrumAction(Context context, Meta an) {
super(context, an);
}
@Override
protected NMFile execute(Logable log, String name, Meta reader, NMFile source) throws ContentException {
protected NMFile execute(Context context, Logable log, String name, Laminate meta, NMFile source) throws ContentException {
log.log("File {} started", source.getName());
List<NMPoint> printPoints = new ArrayList<>();
List<NMPoint> showPoints = new ArrayList<>();
for (NMPoint point : source.getNMPoints()) {
if (toPrint(point)) {
if (toPrint(point, meta)) {
printPoints.add(point);
}
if (toShow(point)) {
if (toShow(point, meta)) {
showPoints.add(point);
}
}
int chanelsPerBin = meta().getInt("binning", 1); // биннинг
boolean normalize = meta().getBoolean("normalize", false); // нормировка на время набора точки
int chanelsPerBin = meta.getInt("binning", 1); // биннинг
boolean normalize = meta.getBoolean("normalize", false); // нормировка на время набора точки
if (showPoints.size() > 0) {
showSpectra(showPoints, source.getName(), chanelsPerBin, normalize);
@ -75,7 +72,7 @@ public class ShowSpectrumAction extends OneToOneAction<NMFile, NMFile> {
if (printPoints.size() > 0) {
ESpectrum data = new ESpectrum(printPoints, chanelsPerBin, normalize);
OutputStream stream = buildActionOutput(name);
OutputStream stream = buildActionOutput(context, name);
ColumnedDataWriter.writeDataSet(stream, data, source.getName());
@ -85,11 +82,9 @@ public class ShowSpectrumAction extends OneToOneAction<NMFile, NMFile> {
return source;
}
private boolean toPrint(NMPoint point) throws ContentException {
Meta root = this.meta();
if (root.hasNode("print")) {
List<? extends Meta> cfg = meta().getNodes("print");
private boolean toPrint(NMPoint point, Meta meta) throws ContentException {
if (meta.hasNode("print")) {
List<? extends Meta> cfg = meta.getNodes("print");
boolean res = false;
for (Meta e : cfg) {
double from = e.getDouble("from", 0);
@ -98,15 +93,13 @@ public class ShowSpectrumAction extends OneToOneAction<NMFile, NMFile> {
}
return res;
} else {
return root.getBoolean("print", false);
return meta.getBoolean("print", false);
}
}
private boolean toShow(NMPoint point) throws ContentException {
Meta root = this.meta();
if (root.hasNode("show")) {
List<? extends Meta> cfg = meta().getNodes("show");
private boolean toShow(NMPoint point, Meta meta) throws ContentException {
if (meta.hasNode("show")) {
List<? extends Meta> cfg = meta.getNodes("show");
boolean res = false;
for (Meta e : cfg) {
double from = e.getDouble("from", 0);
@ -115,7 +108,7 @@ public class ShowSpectrumAction extends OneToOneAction<NMFile, NMFile> {
}
return res;
} else {
return root.getBoolean("show", false);
return meta.getBoolean("show", false);
}
}

View File

@ -21,6 +21,7 @@ import hep.dataforge.description.TypedActionDef;
import hep.dataforge.exceptions.ContentException;
import hep.dataforge.io.ColumnedDataWriter;
import hep.dataforge.io.log.Logable;
import hep.dataforge.meta.Laminate;
import hep.dataforge.meta.Meta;
import inr.numass.data.NMFile;
import inr.numass.data.RawNMPoint;
@ -39,22 +40,18 @@ public class SlicingAction extends OneToOneAction<NMFile, NMFile> {
public static final String name = "slicing";
public SlicingAction(Context context, Meta an) {
super(context, an);
}
@Override
public String getName() {
return name;
}
@Override
protected NMFile execute(Logable log, String name, Meta reader, NMFile source) throws ContentException {
protected NMFile execute(Context context, Logable log, String name, Laminate meta, NMFile source) throws ContentException {
boolean normalize;
Map<String, Pair<Integer, Integer>> slicingConfig;
LinkedHashMap<String, Pair<Integer, Integer>> res = new LinkedHashMap<>();
List<? extends Meta> list = meta().getNode("sliceconfig").getNodes("slicepoint");
List<? extends Meta> list = meta.getNode("sliceconfig").getNodes("slicepoint");
for (Meta slice : list) {
String title = slice.getString("title", slice.getName());
@ -64,7 +61,7 @@ public class SlicingAction extends OneToOneAction<NMFile, NMFile> {
}
slicingConfig = res;
normalize = meta().getBoolean("normalize", false);
normalize = meta.getBoolean("normalize", false);
if (slicingConfig == null) {
throw new RuntimeException("Slice configuration not defined");
@ -73,7 +70,7 @@ public class SlicingAction extends OneToOneAction<NMFile, NMFile> {
SlicedData sData = new SlicedData(source, slicingConfig, normalize);
OutputStream stream = buildActionOutput(name);
OutputStream stream = buildActionOutput(context, name);
ColumnedDataWriter.writeDataSet(stream, sData, null);

View File

@ -18,7 +18,6 @@ package inr.numass.actions;
import hep.dataforge.actions.ManyToOneAction;
import hep.dataforge.actions.GroupBuilder;
import hep.dataforge.context.Context;
import hep.dataforge.data.Data;
import hep.dataforge.data.DataNode;
import hep.dataforge.points.Format;
import hep.dataforge.points.DataPoint;
@ -34,8 +33,7 @@ import java.io.OutputStream;
import java.util.Arrays;
import java.util.List;
import hep.dataforge.points.PointSet;
import java.util.function.Consumer;
import javafx.util.Pair;
import java.util.Map;
/**
*
@ -46,17 +44,13 @@ public class SummaryAction extends ManyToOneAction<FitState, PointSet> {
public static final String SUMMARY_NAME = "sumName";
public SummaryAction(Context context, Meta annotation) {
super(context, annotation);
}
@Override
@SuppressWarnings("unchecked")
protected List<DataNode<PointSet>> buildGroups(DataNode input) {
Meta meta = inputMeta(input.meta());
@SuppressWarnings("unchecked")
protected List<DataNode<PointSet>> buildGroups(Context context, DataNode input, Meta actionMeta) {
Meta meta = inputMeta(context, input.meta(), actionMeta);
List<DataNode<PointSet>> groups;
if (meta.hasValue("grouping.byValue")) {
groups = super.buildGroups(input);
groups = super.buildGroups(context, input, actionMeta);
} else {
groups = GroupBuilder.byValue(SUMMARY_NAME, meta.getString(SUMMARY_NAME, "summary")).group(input);
}
@ -64,8 +58,8 @@ public class SummaryAction extends ManyToOneAction<FitState, PointSet> {
}
@Override
protected PointSet execute(Logable log, DataNode<FitState> input) {
String[] parNames = meta().getStringArray("parnames");
protected PointSet execute(Context context, Logable log, String nodeName, Map<String, FitState> input, Meta meta) {
String[] parNames = meta.getStringArray("parnames");
String[] names = new String[2 * parNames.length + 2];
names[0] = "file";
for (int i = 0; i < parNames.length; i++) {
@ -81,25 +75,22 @@ public class SummaryAction extends ManyToOneAction<FitState, PointSet> {
double[] av = new double[parNames.length];
Arrays.fill(av, 0);
input.stream().forEach(new Consumer<Pair<String, Data<? extends FitState>>>() {
@Override
public void accept(Pair<String, Data<? extends FitState>> item) {
FitState state = item.getValue().get();
Value[] values = new Value[names.length];
values[0] = Value.of(item.getKey());
for (int i = 0; i < parNames.length; i++) {
Value val = Value.of(state.getParameters().getValue(parNames[i]));
values[2 * i + 1] = val;
Value err = Value.of(state.getParameters().getError(parNames[i]));
values[2 * i + 2] = err;
double weight = 1 / err.doubleValue() / err.doubleValue();
av[i] += val.doubleValue() * weight;
weights[i] += weight;
}
values[values.length - 1] = Value.of(state.getChi2());
DataPoint point = new MapPoint(names, values);
res.add(point);
input.forEach((String key, FitState value) -> {
FitState state = value;
Value[] values = new Value[names.length];
values[0] = Value.of(key);
for (int i = 0; i < parNames.length; i++) {
Value val = Value.of(state.getParameters().getValue(parNames[i]));
values[2 * i + 1] = val;
Value err = Value.of(state.getParameters().getError(parNames[i]));
values[2 * i + 2] = err;
double weight = 1 / err.doubleValue() / err.doubleValue();
av[i] += val.doubleValue() * weight;
weights[i] += weight;
}
values[values.length - 1] = Value.of(state.getChi2());
DataPoint point = new MapPoint(names, values);
res.add(point);
});
Value[] averageValues = new Value[names.length];
@ -117,11 +108,11 @@ public class SummaryAction extends ManyToOneAction<FitState, PointSet> {
}
@Override
protected void afterGroup(Logable log, String groupName, Meta outputMeta, PointSet output) {
OutputStream stream = buildActionOutput(groupName);
protected void afterGroup(Context context, Logable log, String groupName, Meta outputMeta, PointSet output) {
OutputStream stream = buildActionOutput(context, groupName);
ColumnedDataWriter.writeDataSet(stream, output, groupName);
super.afterGroup(log, groupName, outputMeta, output);
super.afterGroup(context, log, groupName, outputMeta, output);
}
}

View File

@ -103,8 +103,12 @@ public class ResolutionFunction implements BivariateFunction {
return (double x, double y) -> f.value(x - y);
}
public static BivariateFunction getConstantTail(){
public static BivariateFunction getAngledTail(double dropPerKv) {
return (double E, double U) -> 1 - (E - U) * dropPerKv/1000d;
}
public static BivariateFunction getConstantTail() {
return new ConstantTailFunction();
}

View File

@ -15,7 +15,7 @@
*/
package inr.numass.models;
import hep.dataforge.actions.RunManager;
import hep.dataforge.actions.ActionUtils;
import hep.dataforge.context.Context;
import hep.dataforge.data.DataNode;
import hep.dataforge.io.ColumnedDataReader;
@ -48,7 +48,7 @@ public class TransmissionInterpolator implements UnivariateFunction {
@SuppressWarnings("unchecked")
public static TransmissionInterpolator fromAction(Context context, Meta actionAnnotation,
String xName, String yName, int nSmooth, double w, double border) throws InterruptedException {
DataNode<PointSet> node = RunManager.executeAction(context, actionAnnotation);
DataNode<PointSet> node = ActionUtils.runConfig(context, actionAnnotation);
PointSet data = node.getData().get();
return new TransmissionInterpolator(data, xName, yName, nSmooth, w, border);
}

View File

@ -10,7 +10,7 @@ import de.jensd.shichimifx.utils.ConsoleDude;
import hep.dataforge.actions.Action;
import hep.dataforge.actions.ActionManager;
import hep.dataforge.actions.ActionStateListener;
import hep.dataforge.actions.RunManager;
import hep.dataforge.actions.ActionUtils;
import hep.dataforge.context.Context;
import hep.dataforge.context.GlobalContext;
import hep.dataforge.data.DataNode;
@ -147,7 +147,7 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
* @return
*/
@Override
public StagePane getStagePane(String stage) {
public synchronized StagePane getStagePane(String stage) {
if (!stages.containsKey(stage)) {
Tab stageTab = new Tab(stage);
StagePane stageTabPane = new StagePane();
@ -171,9 +171,9 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
private void buildContextPane() {
Configuration contextValues = new Configuration("context");
//TODO add asMeta method to Context and replace map here
for (Map.Entry<String, Value> item : context.getProperties().entrySet()) {
context.getProperties().entrySet().stream().forEach((item) -> {
contextValues.setValue(item.getKey(), item.getValue());
}
});
contextValues.addObserver(new ConfigChangeListener() {
@Override
@ -310,9 +310,7 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
//FIXME evaluate error here
throw new Error("Empty data");
}
Action action = RunManager.readAction(getContext(), getActionConfiguration());
// action.addListener(this);
action.run(data).compute();
ActionUtils.runAction(getContext(), data, getActionConfiguration()).compute();
Platform.runLater(() -> statusBar.setText("Execution complete"));
}, "actions").start();
}

View File

@ -28,18 +28,20 @@ public class StagePane extends TabPane implements Named {
}
public void closeAll() {
for (OutputTab tab : tabs.values()) {
tabs.values().stream().map((tab) -> {
tab.close();
return tab;
}).forEach((tab) -> {
Platform.runLater(() -> getTabs().remove(tab));
}
});
}
public void closeTab(String name) {
public synchronized void closeTab(String name) {
tabs.get(name).close();
Platform.runLater(() -> getTabs().remove(tabs.get(name)));
}
public TextOutputTab buildTextOutput(String name) {
public synchronized TextOutputTab buildTextOutput(String name) {
if (tabs.containsKey(name)) {
closeTab(name);
}
@ -49,7 +51,7 @@ public class StagePane extends TabPane implements Named {
return out;
}
public PlotFrame buildPlotOutput(String name, Meta meta) {
public synchronized PlotFrame buildPlotOutput(String name, Meta meta) {
if (tabs.containsKey(name)) {
closeTab(name);
}

View File

@ -5,17 +5,18 @@
*/
package inr.numass.workbench;
import hep.dataforge.fx.DataOutputPane;
import hep.dataforge.fx.FXDataOutputPane;
import java.io.OutputStream;
import javafx.event.Event;
/**
* A text output tab. Basically it is attached to IOManager::out
*
* @author Alexander Nozik <altavir@gmail.com>
*/
public class TextOutputTab extends OutputTab {
private final DataOutputPane out;
private final FXDataOutputPane out;
/**
* Create new stream output tab
@ -26,7 +27,8 @@ public class TextOutputTab extends OutputTab {
*/
public TextOutputTab(String name) {
super(name);
out = new DataOutputPane();
// out = new DataOutputPane();
out = new FXDataOutputPane();
setContent(out);
setOnClosed((Event event) -> close());
}