Made ActionManager optional. ActionUtils searches all plugins for exported actions.

This commit is contained in:
Alexander Nozik 2017-03-26 12:45:36 +03:00
parent 237ad3b6c3
commit 0a261ad466
12 changed files with 54 additions and 48 deletions

View File

@ -81,9 +81,9 @@ ListTable data = readData("c:\\Users\\Darksnake\\Dropbox\\PlayGround\\RUN23.DAT"
FitState state = new FitState(data, model, allPars);
FitState res = fm.runDefaultTask(state, "E0", "N", "bkg");
FitState res = fm.runDefaultStage(state, "E0", "N", "bkg");
res = fm.runDefaultTask(res, "E0", "N", "bkg", "mnu2");
res = fm.runDefaultStage(res, "E0", "N", "bkg", "mnu2");
res.print(out);
@ -91,7 +91,7 @@ res.print(out);
//
//// fm.setPriorProb(new GaussianPrior("X", 0.47, 0.47*0.03));
//// fm.setPriorProb(new MultivariateGaussianPrior(allPars.getSubSet("X","trap")));
//res = fm.runTask(res, "MINUIT", "run", "E0", "N", "bkg", "mnu2");
//res = fm.runStage(res, "MINUIT", "run", "E0", "N", "bkg", "mnu2");
////
//res.print(onComplete);

View File

@ -3,7 +3,7 @@ package inr.numass.scripts
import hep.dataforge.context.Global
import hep.dataforge.grind.Grind
import hep.dataforge.meta.Meta
import hep.dataforge.stat.fit.FitPlugin
import hep.dataforge.stat.fit.FitManager
import hep.dataforge.stat.fit.ParamSet
import hep.dataforge.stat.models.XYModel
import inr.numass.NumassPlugin
@ -17,7 +17,7 @@ Locale.setDefault(Locale.US);
new NumassPlugin().startGlobal();
def fm = Global.instance().provide("fitting", FitPlugin.class).getFitManager();
def fm = Global.instance().provide("fitting", FitManager.class).getFitManager();
def mm = fm.modelManager

View File

@ -91,7 +91,7 @@ FitState state = new FitState(data, model, allPars);
//new PlotFitResultAction().eval(state);
FitState res = fm.runTask(state, "QOW", FitStage.TASK_RUN, "N", "bkg", "E0", "U2");
FitState res = fm.runStage(state, "QOW", FitStage.TASK_RUN, "N", "bkg", "E0", "U2");

View File

@ -61,7 +61,7 @@ FittingIOUtils.printSpectrum(new PrintWriter(System.out), spectrum, allPars, 184
//// allPars.setParValue("X", 0.4);
// FitState state = FitTaskManager.buildState(data, model, allPars);
//
// FitState res = fm.runTask(state, "QOW", FitTask.TASK_RUN, "N", "bkg", "pos", "sigma");
// FitState res = fm.runStage(state, "QOW", FitTask.TASK_RUN, "N", "bkg", "pos", "sigma");
//
// res.print(onComplete());

View File

@ -40,7 +40,7 @@ List<NMPoint> pileup = new ArrayList<>();
lowerChannel = 400;
upperChannel = 1800;
PileUpSimulator buildSimulator(NMPoint point, double cr, NMPoint reference = null, boolean extrapolate = true, double scale = 1d) {
PileUpSimulator buildSimulator(NMPoint point, double cr, NMPoint reference = null, boolean extrapolate = false, double scale = 1d) {
def cfg = Grind.buildMeta(cr: cr) {
pulser(mean: 3450, sigma: 86.45, freq: 66.43)
}

View File

@ -73,7 +73,7 @@ FittingIOUtils.printSpectrum(Global.out(), spectrum, allPars, 14000, 18600.0, 40
////new PlotFitResultAction().eval(state);
//
//
//FitState res = fm.runTask(state, "QOW", FitTask.TASK_RUN, "N", "bkg", "E0", "U2", "trap");
//FitState res = fm.runStage(state, "QOW", FitTask.TASK_RUN, "N", "bkg", "E0", "U2", "trap");
//
//
//

View File

@ -95,7 +95,7 @@ FitState state = fm.buildState(data, model, allPars);
// fm.checkDerivs();
// res.print(Out.onComplete);
// fm.checkFitDerivatives();
FitState res = fm.runDefaultTask(state, "U2", "N", "trap");
FitState res = fm.runDefaultStage(state, "U2", "N", "trap");
res.print(out);

View File

@ -19,16 +19,13 @@ import hep.dataforge.actions.ActionManager;
import hep.dataforge.context.Context;
import hep.dataforge.context.Global;
import hep.dataforge.description.ActionDescriptor;
import hep.dataforge.description.DescriptorFormatter;
import hep.dataforge.description.DescriptorUtils;
import hep.dataforge.description.TextDescriptorFormatter;
import hep.dataforge.exceptions.DescriptorException;
import hep.dataforge.io.markup.MarkupBuilder;
import hep.dataforge.io.markup.MarkupUtils;
import hep.dataforge.meta.Meta;
import java.io.PrintWriter;
/**
*
* @author Darksnake
*/
public class Numass {
@ -44,22 +41,30 @@ public class Numass {
}
public static void printDescription(Context context, boolean allowANSI) throws DescriptorException {
PrintWriter writer = new PrintWriter(context.io().out());
DescriptorFormatter formatter = new TextDescriptorFormatter(writer, allowANSI);
writer.println("***Data description***");
writer.print(" ");
formatter.showDescription(
DescriptorUtils.buildDescriptor(
DescriptorUtils.findAnnotatedElement("method::hep.dataforge.data.DataManager.read")
));
writer.println("***Allowed actions***");
MarkupBuilder builder = new MarkupBuilder()
.addText("***Data description***", "red")
.ln()
.addText("\t")
.addContent(
MarkupUtils.markupDescriptor(DescriptorUtils.buildDescriptor("method::hep.dataforge.data.DataManager.read"))
)
.ln()
.addText("***Allowed actions***", "red")
.ln();
for (ActionDescriptor descriptor : context.getPlugin(ActionManager.class).list()) {
builder
.addText("\t")
.addContent(
MarkupUtils.markupDescriptor(descriptor)
);
for (ActionDescriptor descriptor : ActionManager.buildFrom(context).list()) {
writer.print(" ");
formatter.showDescription(descriptor);
}
writer.println("***End of actions list***");
writer.flush();
builder.addText("***End of actions list***", "red");
context.io().getMarkupRenderer().render(builder.build());
}
}

View File

@ -27,7 +27,6 @@ import hep.dataforge.plots.fx.FXPlotUtils;
import hep.dataforge.plots.fx.PlotContainer;
import hep.dataforge.plots.jfreechart.JFreeChartFrame;
import hep.dataforge.stat.fit.FitManager;
import hep.dataforge.stat.fit.FitPlugin;
import hep.dataforge.stat.models.ModelManager;
import hep.dataforge.stat.models.WeightedXYModel;
import hep.dataforge.stat.models.XYModel;
@ -74,11 +73,13 @@ public class NumassPlugin extends BasicPlugin {
// StorageManager.buildFrom(context);
super.attach(context);
context.setIO(new NumassIO());
FitManager fm = context.provide("fitting", FitPlugin.class).getFitManager();
FitManager fm = context.provide("fitting", FitManager.class);
loadModels(fm.getModelManager());
loadMath(MathPlugin.buildFrom(context));
ActionManager actions = ActionManager.buildFrom(context);
ActionManager actions = new ActionManager();
actions.attach(context);
actions.register(SlicingAction.class);
actions.register(PrepareDataAction.class);
actions.register(ReadLegacyDataAction.class);
@ -88,7 +89,6 @@ public class NumassPlugin extends BasicPlugin {
actions.register(SummaryAction.class);
actions.register(PlotDataAction.class);
actions.register(PlotFitResultAction.class);
actions.register(ShowLossSpectrumAction.class);
actions.register(AdjustErrorsAction.class);
actions.register(ShowEnergySpectrumAction.class);
actions.register(SubstractSpectrumAction.class);
@ -124,16 +124,16 @@ public class NumassPlugin extends BasicPlugin {
*/
private void loadModels(ModelManager manager) {
manager.addModel("modularbeta", (context, an) -> {
double A = an.getDouble("resolution", 8.3e-5);//8.3e-5
double from = an.getDouble("from", 14400d);
double to = an.getDouble("to", 19010d);
RangedNamedSetSpectrum beta = new BetaSpectrum(getClass().getResourceAsStream("/data/FS.txt"));
ModularSpectrum sp = new ModularSpectrum(beta, A, from, to);
NBkgSpectrum spectrum = new NBkgSpectrum(sp);
return new XYModel(spectrum, getAdapter(an));
});
// manager.addModel("modularbeta", (context, an) -> {
// double A = an.getDouble("resolution", 8.3e-5);//8.3e-5
// double from = an.getDouble("from", 14400d);
// double to = an.getDouble("to", 19010d);
// RangedNamedSetSpectrum beta = new BetaSpectrum(getClass().getResourceAsStream("/data/FS.txt"));
// ModularSpectrum sp = new ModularSpectrum(beta, A, from, to);
// NBkgSpectrum spectrum = new NBkgSpectrum(sp);
//
// return new XYModel(spectrum, getAdapter(an));
// });
manager.addModel("scatter", (context, an) -> {
double A = an.getDouble("resolution", 8.3e-5);//8.3e-5

View File

@ -62,6 +62,7 @@ public class TestModels {
}
}
@SuppressWarnings("deprecation")
private static ParametricFunction oldModel(Context context, Meta meta) {
double A = meta.getDouble("resolution", meta.getDouble("resolution.width", 8.3e-5));//8.3e-5
double from = meta.getDouble("from", 13900d);

View File

@ -52,11 +52,11 @@ public class NumassFitScanTask extends AbstractTask<FitState> {
//do fit
Meta fitConfig = config.getMeta("fit");
sourceNode.forEachDataWithType(Table.class, d -> {
sourceNode.dataStream().forEach(table -> {
for (int i = 0; i < scanValues.listValue().size(); i++) {
Value val = scanValues.listValue().get(i);
MetaBuilder overrideMeta = new MetaBuilder(fitConfig);
overrideMeta.setValue("@resultName", String.format("%s[%s=%s]", d.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);
@ -65,8 +65,8 @@ public class NumassFitScanTask extends AbstractTask<FitState> {
.filter(par -> par.getString("name") == scanParameter).forEach(par -> par.setValue("value", val));
}
// Data<Table> newData = new Data<Table>(data.getGoal(),data.type(),overrideMeta);
DataNode node = action.run(model.getContext(), DataNode.of("fit_" + i, d, Meta.empty()), overrideMeta);
resultBuilder.putData(d.getName() + ".fit_" + i, node.getData());
DataNode<FitState> node = action.run(model.getContext(), DataNode.of("fit_" + i, table, Meta.empty()), overrideMeta);
resultBuilder.putData(table.getName() + ".fit_" + i, node.getData());
}
});

View File

@ -100,7 +100,7 @@ public class PileUpSimulator {
* @return
*/
private boolean nextEventRegistered(short prevChanel, double delay) {
double average = 6.76102 - 4.31897E-4 * prevChanel + 7.88429E-8 * prevChanel * prevChanel;
double average = 6.76102 - 4.31897E-4 * prevChanel + 7.88429E-8 * prevChanel * prevChanel + 0.2;
double prob = 1d - 1d / (1d + Math.pow(delay / average, 75.91));
return random(prob);
}